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/labstack/echo/v4"
"github.com/spf13/viper" "github.com/spf13/viper"
"git.agecem.com/agecem/bottin-agenda/responses"
bottindata "git.agecem.com/agecem/bottin/v5/data" bottindata "git.agecem.com/agecem/bottin/v5/data"
) )
@ -25,23 +26,31 @@ func GetMembre(c echo.Context) error {
membreID := c.Param("membre_id") membreID := c.Param("membre_id")
getMembreResponse := responses.GetMembreResponse{}
membre, err := bottinConnection.GetMembre(membreID) membre, err := bottinConnection.GetMembre(membreID)
if err != nil { if err != nil {
if err.Error() == "No membre by that id was found" { getMembreResponse.Message = err.Error()
return c.JSON(http.StatusNotFound, map[string]string{
"message": "Not Found", var statusCode int
})
} switch err.Error() {
return c.JSON(http.StatusInternalServerError, map[string]string{ case "Veuillez fournir un numéro étudiant à rechercher":
"message": "Unknown error during GetMembre", statusCode = http.StatusBadRequest
"error": err.Error(), case "Ce numéro étudiant ne correspond à aucunE membre":
}) statusCode = http.StatusNotFound
default:
statusCode = http.StatusInternalServerError
} }
return c.JSON(http.StatusOK, map[string]interface{}{ getMembreResponse.Data.Membre = membre
"message": "Read successful",
"data": map[string]interface{}{ return c.JSON(statusCode, getMembreResponse)
"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"`
}