bottin/handlers/read.go

32 lines
682 B
Go
Raw Normal View History

2023-05-25 01:21:09 -05:00
package handlers
import (
"net/http"
"github.com/labstack/echo/v4"
)
func (h *Handler) ReadMembre(c echo.Context) error {
2023-05-25 01:21:09 -05:00
membreID := c.Param("membre_id")
membre, err := h.DataClient.GetMembre(membreID)
2023-05-25 01:21:09 -05: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,
},
})
}