implement dbhandler package and new test file

This commit is contained in:
Adrian Zürcher
2025-10-31 08:11:07 +01:00
parent 1568ee2482
commit 80675ed328
17 changed files with 674 additions and 572 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"time"
"gitea.tecamino.com/paadi/tecamino-logger/logging"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
@@ -14,7 +15,7 @@ type API struct {
router *gin.Engine
}
func NewAPI(host string, port int) *API {
func NewAPI(host string, port int, logger *logging.Logger) (*API, error) {
r := gin.Default()
r.Use(cors.New(cors.Config{
//AllowOrigins: []string{"http://localhost:9000"}, // frontend origin
@@ -26,14 +27,17 @@ func NewAPI(host string, port int) *API {
MaxAge: 12 * time.Hour,
}))
apiHandler := NewAPIHandler()
apiHandler, err := NewAPIHandler(logger)
if err != nil {
return nil, err
}
v1 := r.Group("v1")
v1.GET("/events", apiHandler.GetEventById)
v1.GET("/events", apiHandler.GetEvent)
v1.GET("/events/new", apiHandler.StartNewEvent)
v1.GET("/events/delete", apiHandler.DeleteEvent)
v1.GET("/members", apiHandler.GetMemberById)
v1.GET("/responsible", apiHandler.GetResponsibleById)
v1.GET("/members", apiHandler.GetMember)
v1.GET("/responsible", apiHandler.GetResponsible)
v1.POST("/database/open", apiHandler.OpenDatabase)
v1.POST("/members/add", apiHandler.AddNewMember)
@@ -50,7 +54,7 @@ func NewAPI(host string, port int) *API {
return &API{host: host,
port: port,
router: r,
}
}, nil
}
func (api *API) Run() error {