diff --git a/cmd/api.go b/cmd/api.go index e7cefd4..3f2156e 100644 --- a/cmd/api.go +++ b/cmd/api.go @@ -55,6 +55,8 @@ var apiCmd = &cobra.Command{ // Routes + e.POST("/v2/seed/", handlers.PostSeed) + e.GET("/v2/health/", handlers.GetHealth) e.GET("/v2/membres/:membre_id/", handlers.GetMembre) diff --git a/handlers/seed.go b/handlers/seed.go new file mode 100644 index 0000000..788baef --- /dev/null +++ b/handlers/seed.go @@ -0,0 +1,35 @@ +package handlers + +import ( + "fmt" + "net/http" + + "git.agecem.com/agecem/bottin-agenda/data" + "git.agecem.com/agecem/bottin-agenda/responses" + "github.com/labstack/echo/v4" +) + +func PostSeed(c echo.Context) error { + var response responses.PostSeedResponse + var statusCode int = http.StatusInternalServerError + + client, err := data.NewDataClientFromViper() + if err != nil { + response.Message = fmt.Sprintf("Error during data.NewDataClientFromViper(): %s", err) + + return c.JSON(statusCode, response) + } + + _, err = client.Seed() + if err != nil { + response.Message = fmt.Sprintf("Error during client.Seed(): %s", err) + + return c.JSON(statusCode, response) + } + + response.Message = "Seed seems successful" + + statusCode = http.StatusOK + + return c.JSON(statusCode, response) +} diff --git a/responses/responses.go b/responses/responses.go index 64406af..f703f97 100644 --- a/responses/responses.go +++ b/responses/responses.go @@ -2,9 +2,24 @@ package responses import bottinmodels "git.agecem.com/agecem/bottin/v5/models" -type GetMembreResponse struct { +type PostSeedResponse struct { Message string `json:"message"` - Data struct { - Membre bottinmodels.Membre - } `json:"data"` +} + +type GetMembreResponseData struct { + Membre bottinmodels.Membre `json:"membre"` +} + +type GetMembreResponse struct { + Message string `json:"message"` + Data GetMembreResponseData `json:"data"` +} + +type PostTransactionsResponseData struct { + RowsInserted int64 `json:"rows_inserted"` +} + +type PostTransactionsResponse struct { + Message string `json:"message"` + Data PostTransactionsResponseData `json:"data"` }