From 5915e3ca7b44148de1d0730c63ceed57c140ff81 Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Thu, 8 Jun 2023 20:47:39 -0400 Subject: [PATCH 1/4] Retirer route GET /v2/membres/:membre_id MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cleanup code désuet (et redondant avec agecem/bottin) en lien avec le concept de Membre --- cmd/api.go | 2 -- handlers/membre.go | 56 ------------------------------------------ responses/responses.go | 10 -------- 3 files changed, 68 deletions(-) delete mode 100644 handlers/membre.go diff --git a/cmd/api.go b/cmd/api.go index 018fbc1..03b6e30 100644 --- a/cmd/api.go +++ b/cmd/api.go @@ -59,8 +59,6 @@ var apiCmd = &cobra.Command{ e.GET("/v2/health/", handlers.GetHealth) - e.GET("/v2/membres/:membre_id/", handlers.GetMembre) - e.GET("/v2/transactions/", handlers.GetTransactions) e.POST("/v2/transactions/", handlers.PostTransactions) 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/responses/responses.go b/responses/responses.go index fcadcce..7ac2507 100644 --- a/responses/responses.go +++ b/responses/responses.go @@ -2,22 +2,12 @@ package responses import ( "git.agecem.com/agecem/bottin-agenda/models" - bottinmodels "git.agecem.com/agecem/bottin/v5/models" ) 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"` } -- 2.45.2 From fe1caec61e58211ed5d9d6afe56b9554e0564e35 Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Thu, 8 Jun 2023 21:05:25 -0400 Subject: [PATCH 2/4] Bump all routes /v2 -> /v3 --- cmd/api.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/api.go b/cmd/api.go index 03b6e30..7297270 100644 --- a/cmd/api.go +++ b/cmd/api.go @@ -55,12 +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/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 -- 2.45.2 From 53c5d8f1c6b2180816da99090b001ec187ba952a Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Thu, 8 Jun 2023 21:06:04 -0400 Subject: [PATCH 3/4] [BREAKING] Ajouter response.Data pour GetHealth MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implémenter GetHealthResponse et GetHealthResponseData --- handlers/health.go | 15 ++++++++++----- responses/responses.go | 10 ++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) 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/responses/responses.go b/responses/responses.go index 7ac2507..e54f155 100644 --- a/responses/responses.go +++ b/responses/responses.go @@ -4,6 +4,16 @@ import ( "git.agecem.com/agecem/bottin-agenda/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"` } -- 2.45.2 From 600e22a645d8cf95ad301200cc148ab9813fc586 Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Thu, 8 Jun 2023 21:08:20 -0400 Subject: [PATCH 4/4] =?UTF-8?q?Retirer=20num=C3=A9ro=20de=20version=20de?= =?UTF-8?q?=20docstring?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handlers/transaction.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 -- 2.45.2