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 20:41:13 -04:00
|
|
|
"git.agecem.com/agecem/bottin-agenda/responses"
|
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")
|
|
|
|
|
2023-06-03 20:41:13 -04:00
|
|
|
getMembreResponse := responses.GetMembreResponse{}
|
|
|
|
|
2023-05-30 19:03:55 -04:00
|
|
|
membre, err := bottinConnection.GetMembre(membreID)
|
|
|
|
if err != nil {
|
2023-06-03 20:41:13 -04:00
|
|
|
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
|
2023-05-30 19:03:55 -04:00
|
|
|
}
|
2023-06-03 20:41:13 -04:00
|
|
|
|
|
|
|
getMembreResponse.Data.Membre = membre
|
|
|
|
|
|
|
|
return c.JSON(statusCode, getMembreResponse)
|
2023-05-30 19:03:55 -04:00
|
|
|
}
|
|
|
|
|
2023-06-03 20:41:13 -04:00
|
|
|
getMembreResponse.Data.Membre = membre
|
|
|
|
|
|
|
|
getMembreResponse.Message = "Read successful"
|
|
|
|
|
|
|
|
return c.JSON(http.StatusOK, getMembreResponse)
|
2023-05-30 19:03:55 -04:00
|
|
|
}
|