bottin/handlers/update.go

43 lines
899 B
Go
Raw Permalink Normal View History

2023-05-25 04:31:29 -04:00
package handlers
import (
"net/http"
"github.com/labstack/echo/v4"
)
func (h *Handler) PutMembrePreferedName(c echo.Context) error {
2023-05-25 04:31:29 -04:00
membreID := c.Param("membre_id")
var newName string
err := c.Bind(&newName)
2023-05-25 04:31:29 -04:00
if err != nil {
return c.JSON(http.StatusBadRequest, map[string]string{
"message": "Could not bind newName",
"error": err.Error(),
})
}
rows, err := h.DataClient.UpdateMembreName(membreID, newName)
2023-05-25 04:31:29 -04:00
if err != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{
"message": "Could not update membre name",
"error": err.Error(),
})
}
if rows == 0 {
return c.JSON(http.StatusBadRequest, map[string]string{
"message": "No update was done, probably no membre by that id",
})
}
return c.JSON(http.StatusOK, map[string]interface{}{
"message": "Update successful",
"data": map[string]interface{}{
"rows": rows,
},
})
}