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

43 lines
899 B
Go

package handlers
import (
"net/http"
"github.com/labstack/echo/v4"
)
func (h *Handler) PutMembrePreferedName(c echo.Context) error {
membreID := c.Param("membre_id")
var newName string
err := c.Bind(&newName)
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)
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,
},
})
}