Bump API à version 2 #2

Merged
vlbeaudoin merged 9 commits from bump/v2 into main 2023-06-03 20:42:35 -04:00
2 changed files with 33 additions and 14 deletions
Showing only changes of commit d6573287f4 - Show all commits

View file

@ -6,6 +6,7 @@ import (
"github.com/labstack/echo/v4"
"github.com/spf13/viper"
"git.agecem.com/agecem/bottin-agenda/responses"
bottindata "git.agecem.com/agecem/bottin/v5/data"
)
@ -25,23 +26,31 @@ func GetMembre(c echo.Context) error {
membreID := c.Param("membre_id")
getMembreResponse := responses.GetMembreResponse{}
membre, err := bottinConnection.GetMembre(membreID)
if err != nil {
if err.Error() == "No membre by that id was found" {
return c.JSON(http.StatusNotFound, map[string]string{
"message": "Not Found",
})
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
}
return c.JSON(http.StatusInternalServerError, map[string]string{
"message": "Unknown error during GetMembre",
"error": err.Error(),
})
getMembreResponse.Data.Membre = membre
return c.JSON(statusCode, getMembreResponse)
}
return c.JSON(http.StatusOK, map[string]interface{}{
"message": "Read successful",
"data": map[string]interface{}{
"membre": &membre,
},
})
getMembreResponse.Data.Membre = membre
getMembreResponse.Message = "Read successful"
return c.JSON(http.StatusOK, getMembreResponse)
}

10
responses/responses.go Normal file
View file

@ -0,0 +1,10 @@
package responses
import bottinmodels "git.agecem.com/agecem/bottin/v5/models"
type GetMembreResponse struct {
Message string `json:"message"`
Data struct {
Membre bottinmodels.Membre
} `json:"data"`
}