49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"git.agecem.com/agecem/bottin/v5/data"
|
|
"github.com/labstack/echo/v4"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
func ReadMembre(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")
|
|
|
|
membre, err := client.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,
|
|
},
|
|
})
|
|
}
|