56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
"github.com/spf13/viper"
|
|
|
|
"git.agecem.com/agecem/bottin-agenda/responses"
|
|
bottindata "git.agecem.com/agecem/bottin/v5/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")
|
|
|
|
getMembreResponse := responses.GetMembreResponse{}
|
|
|
|
membre, err := bottinConnection.GetMembre(membreID)
|
|
if err != nil {
|
|
getMembreResponse.Message = err.Error()
|
|
|
|
var statusCode int
|
|
|
|
switch err.Error() {
|
|
case "Veuillez fournir un numéro étudiant à rechercher":
|
|
statusCode = http.StatusBadRequest
|
|
case "Ce numéro étudiant ne correspond à aucunE membre":
|
|
statusCode = http.StatusNotFound
|
|
default:
|
|
statusCode = http.StatusInternalServerError
|
|
}
|
|
|
|
getMembreResponse.Data.Membre = membre
|
|
|
|
return c.JSON(statusCode, getMembreResponse)
|
|
}
|
|
|
|
getMembreResponse.Data.Membre = membre
|
|
|
|
getMembreResponse.Message = "Read successful"
|
|
|
|
return c.JSON(http.StatusOK, getMembreResponse)
|
|
}
|