bottin/handlers/read.go
2023-09-18 22:55:40 -04:00

32 lines
682 B
Go

package handlers
import (
"net/http"
"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,
},
})
}