Victor Lacasse-Beaudoin
a8dcdd0388
Tag v6.0.0 est sorti mais n'était pas réflété dans le code. BREAKING: API est maintenant exposé sur `/v6` et non `/v5`
61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
package handlers
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"git.agecem.com/agecem/bottin/v6/responses"
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
func (h *Handler) ReadMembre(c echo.Context) error {
|
|
membreID := c.Param("membre_id")
|
|
|
|
membre, err := h.DataClient.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",
|
|
})
|
|
}
|
|
return c.JSON(http.StatusInternalServerError, map[string]string{
|
|
"message": "Unknown error during GetMembre",
|
|
"error": err.Error(),
|
|
})
|
|
}
|
|
|
|
return c.JSON(http.StatusOK, map[string]interface{}{
|
|
"message": "Read successful",
|
|
"data": map[string]interface{}{
|
|
"membre": &membre,
|
|
},
|
|
})
|
|
}
|
|
|
|
func (h *Handler) ListMembres(c echo.Context) error {
|
|
var r responses.ListMembresResponse
|
|
|
|
membres, err := h.DataClient.GetMembres()
|
|
if err != nil {
|
|
r.StatusCode = http.StatusInternalServerError
|
|
r.Error = err.Error()
|
|
r.Message = "Error during (*handlers.Handler).DataClient.GetMembres"
|
|
|
|
return c.JSON(r.StatusCode, r)
|
|
}
|
|
|
|
r.StatusCode = http.StatusOK
|
|
|
|
switch membres := len(membres); membres {
|
|
case 0:
|
|
r.Message = "No membres returned from database"
|
|
case 1:
|
|
r.Message = "Membre returned from database"
|
|
default:
|
|
r.Message = fmt.Sprintf("%d membres returned from database", membres)
|
|
}
|
|
|
|
r.Data.Membres = membres
|
|
|
|
return c.JSON(r.StatusCode, r)
|
|
}
|