Ajouter obtention de membre par API
Utiliser client API de bottin version 4 Ajouter handler GetMembre à `GET /v2/membres/{membre_id} HTTP/1.1`
This commit is contained in:
parent
b283221728
commit
bcd12582f1
4 changed files with 58 additions and 11 deletions
handlers
47
handlers/membre.go
Normal file
47
handlers/membre.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
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,
|
||||
},
|
||||
})
|
||||
}
|
Reference in a new issue