diff --git a/apihandler/apihandler.go b/apihandler/apihandler.go index e051ce1..8c4bd8e 100644 --- a/apihandler/apihandler.go +++ b/apihandler/apihandler.go @@ -6,6 +6,7 @@ import ( "net/http" "git.agecem.com/agecem/bottin-ag/apiresponse" + "git.agecem.com/agecem/bottin-ag/dbclient" bottindata "git.agecem.com/agecem/bottin/v5/data" "github.com/labstack/echo/v4" ) @@ -26,6 +27,7 @@ routes */ type APIHandler struct { BottinAPIClient *bottindata.ApiClient + DBClient *dbclient.DBClient } // HealthGET is the handler for `GET /v:version/health/ http/1.1` diff --git a/cmd/api.go b/cmd/api.go index 71e1304..c55e4b2 100644 --- a/cmd/api.go +++ b/cmd/api.go @@ -9,6 +9,7 @@ import ( "git.agecem.com/agecem/bottin-ag/apihandler" "git.agecem.com/agecem/bottin-ag/config" + "git.agecem.com/agecem/bottin-ag/dbclient" bottindata "git.agecem.com/agecem/bottin/v5/data" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" @@ -35,6 +36,17 @@ var apiCmd = &cobra.Command{ handler.BottinAPIClient = bottindata.NewApiClient("bottin", "localhost", "http", 1312) + dbClient, err := dbclient.New("db", "bottinag", "bottinag", "bottinag", 5432, false) + if err != nil { + log.Fatal(err) + } + + handler.DBClient = dbClient + + if err := handler.DBClient.CreateTablesIfNotExist(); err != nil { + log.Fatal(err) + } + apihandler.DeclareRoutes(v0, &handler) e.Start(fmt.Sprintf(":%d", cfg.API.Port))