2023-05-30 19:03:55 -04:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
|
2023-06-03 19:48:37 -04:00
|
|
|
bottindata "git.agecem.com/agecem/bottin/v5/data"
|
2023-05-30 19:03:55 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|