bcd12582f1
Utiliser client API de bottin version 4 Ajouter handler GetMembre à `GET /v2/membres/{membre_id} HTTP/1.1`
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
"github.com/spf13/viper"
|
|
|
|
bottindata "git.agecem.com/agecem/bottin/v4/data"
|
|
)
|
|
|
|
func GetMembre(c echo.Context) error {
|
|
bottinApiKey := viper.GetString("bottin.api.key")
|
|
bottinApiHost := viper.GetString("bottin.api.host")
|
|
bottinApiProtocol := viper.GetString("bottin.api.protocol")
|
|
bottinApiPort := viper.GetInt("bottin.api.port")
|
|
|
|
// Using bottin's API client
|
|
bottinConnection := bottindata.NewApiClient(
|
|
bottinApiKey,
|
|
bottinApiHost,
|
|
bottinApiProtocol,
|
|
bottinApiPort,
|
|
)
|
|
|
|
membreID := c.Param("membre_id")
|
|
|
|
membre, err := bottinConnection.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,
|
|
},
|
|
})
|
|
}
|