2023-05-25 02:21:09 -04:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
2023-09-19 19:09:51 -04:00
|
|
|
"fmt"
|
2023-05-25 02:21:09 -04:00
|
|
|
"net/http"
|
|
|
|
|
2023-09-19 19:09:51 -04:00
|
|
|
"git.agecem.com/agecem/bottin/v5/responses"
|
2023-05-25 02:21:09 -04:00
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
)
|
|
|
|
|
2023-09-18 22:55:40 -04:00
|
|
|
func (h *Handler) ReadMembre(c echo.Context) error {
|
2023-05-25 02:21:09 -04:00
|
|
|
membreID := c.Param("membre_id")
|
|
|
|
|
2023-09-18 22:55:40 -04:00
|
|
|
membre, err := h.DataClient.GetMembre(membreID)
|
2023-05-25 02:21:09 -04:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2023-09-19 19:09:51 -04:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|