Ajouter update de membre.prefered_name

This commit is contained in:
Victor Lacasse-Beaudoin 2023-05-25 04:31:29 -04:00
parent f1a4d190df
commit b9044fa08d
4 changed files with 79 additions and 6 deletions

View file

@ -36,9 +36,8 @@ func PostMembres(c echo.Context) error {
}
if len(membres) == 0 {
return c.JSON(http.StatusBadRequest, map[string]string{
return c.JSON(http.StatusOK, map[string]string{
"message": "Nothing to do",
"error": "No valid membres to insert were found",
})
}
@ -50,7 +49,7 @@ func PostMembres(c echo.Context) error {
})
}
return c.JSON(http.StatusOK, map[string]interface{}{
return c.JSON(http.StatusCreated, map[string]interface{}{
"message": "Insert successful",
"data": map[string]interface{}{
"membres": newMembres,
@ -85,9 +84,8 @@ func PostProgrammes(c echo.Context) error {
}
if len(programmes) == 0 {
return c.JSON(http.StatusBadRequest, map[string]string{
return c.JSON(http.StatusOK, map[string]string{
"message": "Nothing to do",
"error": "No valid programmes to insert were found",
})
}
@ -99,7 +97,7 @@ func PostProgrammes(c echo.Context) error {
})
}
return c.JSON(http.StatusOK, map[string]interface{}{
return c.JSON(http.StatusCreated, map[string]interface{}{
"message": "Insert successful",
"data": map[string]interface{}{
"programmes": newProgrammes,

60
v4/handlers/update.go Normal file
View file

@ -0,0 +1,60 @@
package handlers
import (
"net/http"
"git.agecem.com/agecem/bottin/v4/data"
"github.com/labstack/echo/v4"
"github.com/spf13/viper"
)
func PutMembrePreferedName(c echo.Context) error {
connection := data.PostgresConnection{
User: viper.GetString("db.user"),
Password: viper.GetString("db.password"),
Host: viper.GetString("db.host"),
Database: viper.GetString("db.database"),
Port: viper.GetInt("db.port"),
}
client, err := data.NewDataClient(connection)
if err != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{
"message": "Could not establish database connection",
"error": err.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 := client.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,
},
})
}