diff --git a/cmd/api.go b/cmd/api.go index 018fbc1..7297270 100644 --- a/cmd/api.go +++ b/cmd/api.go @@ -55,14 +55,12 @@ var apiCmd = &cobra.Command{ // Routes - e.POST("/v2/seed/", handlers.PostSeed) + e.POST("/v3/seed/", handlers.PostSeed) - e.GET("/v2/health/", handlers.GetHealth) + e.GET("/v3/health/", handlers.GetHealth) - e.GET("/v2/membres/:membre_id/", handlers.GetMembre) - - e.GET("/v2/transactions/", handlers.GetTransactions) - e.POST("/v2/transactions/", handlers.PostTransactions) + e.GET("/v3/transactions/", handlers.GetTransactions) + e.POST("/v3/transactions/", handlers.PostTransactions) // Check bottin is ready diff --git a/handlers/health.go b/handlers/health.go index 47d8177..f193544 100644 --- a/handlers/health.go +++ b/handlers/health.go @@ -4,12 +4,16 @@ import ( "net/http" "git.agecem.com/agecem/bottin-agenda/data" + "git.agecem.com/agecem/bottin-agenda/responses" bottindata "git.agecem.com/agecem/bottin/v5/data" "github.com/labstack/echo/v4" "github.com/spf13/viper" ) func GetHealth(c echo.Context) error { + var response responses.GetHealthResponse + var statusCode int = http.StatusNotImplemented + bottinApiKey := viper.GetString("bottin.api.key") bottinApiHost := viper.GetString("bottin.api.host") bottinApiProtocol := viper.GetString("bottin.api.protocol") @@ -48,9 +52,10 @@ func GetHealth(c echo.Context) error { } } - return c.JSON(http.StatusOK, map[string]string{ - "message": "Bottin-agenda API v2 is ready", - "bottin": bottinStatus, - "database": databaseStatus, - }) + statusCode = http.StatusOK + response.Message = "Bottin-agenda API v3 is ready" + response.Data.Bottin = bottinStatus + response.Data.Database = databaseStatus + + return c.JSON(statusCode, response) } diff --git a/handlers/membre.go b/handlers/membre.go deleted file mode 100644 index 67b5215..0000000 --- a/handlers/membre.go +++ /dev/null @@ -1,56 +0,0 @@ -package handlers - -import ( - "net/http" - - "github.com/labstack/echo/v4" - "github.com/spf13/viper" - - "git.agecem.com/agecem/bottin-agenda/responses" - bottindata "git.agecem.com/agecem/bottin/v5/data" -) - -func GetMembre(c echo.Context) error { - bottinApiKey := viper.GetString("bottin.api.key") - bottinApiHost := viper.GetString("bottin.api.host") - bottinApiProtocol := viper.GetString("bottin.api.protocol") - bottinApiPort := viper.GetInt("bottin.api.port") - - // Using bottin's API client - bottinConnection := bottindata.NewApiClient( - bottinApiKey, - bottinApiHost, - bottinApiProtocol, - bottinApiPort, - ) - - membreID := c.Param("membre_id") - - getMembreResponse := responses.GetMembreResponse{} - - membre, err := bottinConnection.GetMembre(membreID) - if err != nil { - getMembreResponse.Message = err.Error() - - var statusCode int - - switch err.Error() { - case "Veuillez fournir un numéro étudiant à rechercher": - statusCode = http.StatusBadRequest - case "Ce numéro étudiant ne correspond à aucunE membre": - statusCode = http.StatusNotFound - default: - statusCode = http.StatusInternalServerError - } - - getMembreResponse.Data.Membre = membre - - return c.JSON(statusCode, getMembreResponse) - } - - getMembreResponse.Data.Membre = membre - - getMembreResponse.Message = "Read successful" - - return c.JSON(http.StatusOK, getMembreResponse) -} diff --git a/handlers/transaction.go b/handlers/transaction.go index ccc77b6..ecd20d9 100644 --- a/handlers/transaction.go +++ b/handlers/transaction.go @@ -12,7 +12,7 @@ import ( "github.com/spf13/viper" ) -// GetTransactions lists transactions on GET /v2/transactions http/1.1 +// GetTransactions handles the listing of transactions func GetTransactions(c echo.Context) error { var statusCode int = http.StatusInternalServerError var response responses.GetTransactionsResponse @@ -46,7 +46,7 @@ func GetTransactions(c echo.Context) error { return c.JSON(statusCode, response) } -// PostTransactions creates transactions on POST /v2/transactions http/1.1 +// PostTransactions handles the creation of transactions func PostTransactions(c echo.Context) error { var statusCode int = http.StatusInternalServerError var response responses.PostTransactionsResponse diff --git a/responses/responses.go b/responses/responses.go index fcadcce..e54f155 100644 --- a/responses/responses.go +++ b/responses/responses.go @@ -2,22 +2,22 @@ package responses import ( "git.agecem.com/agecem/bottin-agenda/models" - bottinmodels "git.agecem.com/agecem/bottin/v5/models" ) +type GetHealthResponseData struct { + Bottin string `json:"bottin"` + Database string `json:"database"` +} + +type GetHealthResponse struct { + Message string `json:"message"` + Data GetHealthResponseData `json:"data"` +} + type PostSeedResponse struct { Message string `json:"message"` } -type GetMembreResponseData struct { - Membre bottinmodels.Membre `json:"membre"` -} - -type GetMembreResponse struct { - Message string `json:"message"` - Data GetMembreResponseData `json:"data"` -} - type PostTransactionsResponseData struct { Transactions []models.Transaction `json:"transactions"` }