Merge pull request '[BREAKING] Bump à version 3' (#15) from breaking/remove-membre-route into main

Reviewed-on: #15
This commit is contained in:
Victor Lacasse-Beaudoin 2023-06-08 20:11:27 -05:00
commit f9a51ad685
5 changed files with 26 additions and 79 deletions

View file

@ -55,14 +55,12 @@ var apiCmd = &cobra.Command{
// Routes // 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("/v3/transactions/", handlers.GetTransactions)
e.POST("/v3/transactions/", handlers.PostTransactions)
e.GET("/v2/transactions/", handlers.GetTransactions)
e.POST("/v2/transactions/", handlers.PostTransactions)
// Check bottin is ready // Check bottin is ready

View file

@ -4,12 +4,16 @@ import (
"net/http" "net/http"
"git.agecem.com/agecem/bottin-agenda/data" "git.agecem.com/agecem/bottin-agenda/data"
"git.agecem.com/agecem/bottin-agenda/responses"
bottindata "git.agecem.com/agecem/bottin/v5/data" bottindata "git.agecem.com/agecem/bottin/v5/data"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
func GetHealth(c echo.Context) error { func GetHealth(c echo.Context) error {
var response responses.GetHealthResponse
var statusCode int = http.StatusNotImplemented
bottinApiKey := viper.GetString("bottin.api.key") bottinApiKey := viper.GetString("bottin.api.key")
bottinApiHost := viper.GetString("bottin.api.host") bottinApiHost := viper.GetString("bottin.api.host")
bottinApiProtocol := viper.GetString("bottin.api.protocol") bottinApiProtocol := viper.GetString("bottin.api.protocol")
@ -48,9 +52,10 @@ func GetHealth(c echo.Context) error {
} }
} }
return c.JSON(http.StatusOK, map[string]string{ statusCode = http.StatusOK
"message": "Bottin-agenda API v2 is ready", response.Message = "Bottin-agenda API v3 is ready"
"bottin": bottinStatus, response.Data.Bottin = bottinStatus
"database": databaseStatus, response.Data.Database = databaseStatus
})
return c.JSON(statusCode, response)
} }

View file

@ -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)
}

View file

@ -12,7 +12,7 @@ import (
"github.com/spf13/viper" "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 { func GetTransactions(c echo.Context) error {
var statusCode int = http.StatusInternalServerError var statusCode int = http.StatusInternalServerError
var response responses.GetTransactionsResponse var response responses.GetTransactionsResponse
@ -46,7 +46,7 @@ func GetTransactions(c echo.Context) error {
return c.JSON(statusCode, response) 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 { func PostTransactions(c echo.Context) error {
var statusCode int = http.StatusInternalServerError var statusCode int = http.StatusInternalServerError
var response responses.PostTransactionsResponse var response responses.PostTransactionsResponse

View file

@ -2,22 +2,22 @@ package responses
import ( import (
"git.agecem.com/agecem/bottin-agenda/models" "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 { type PostSeedResponse struct {
Message string `json:"message"` 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 { type PostTransactionsResponseData struct {
Transactions []models.Transaction `json:"transactions"` Transactions []models.Transaction `json:"transactions"`
} }