2023-05-25 04:31:29 -04:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
)
|
|
|
|
|
2023-09-18 22:55:40 -04:00
|
|
|
func (h *Handler) PutMembrePreferedName(c echo.Context) error {
|
2023-05-25 04:31:29 -04:00
|
|
|
membreID := c.Param("membre_id")
|
|
|
|
|
|
|
|
var newName string
|
|
|
|
|
2023-09-18 22:55:40 -04:00
|
|
|
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(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-09-18 22:55:40 -04:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|