[BREAKING] Bump à version 3 #15
5 changed files with 26 additions and 79 deletions
10
cmd/api.go
10
cmd/api.go
|
@ -55,14 +55,12 @@ var apiCmd = &cobra.Command{
|
|||
|
||||
// Routes
|
||||
|
||||
e.POST("/v2/seed/", handlers.PostSeed)
|
||||
e.POST("/v3/seed/", handlers.PostSeed)
|
||||
|
||||
e.GET("/v2/health/", handlers.GetHealth)
|
||||
e.GET("/v3/health/", handlers.GetHealth)
|
||||
|
||||
e.GET("/v2/membres/:membre_id/", handlers.GetMembre)
|
||||
|
||||
e.GET("/v2/transactions/", handlers.GetTransactions)
|
||||
e.POST("/v2/transactions/", handlers.PostTransactions)
|
||||
e.GET("/v3/transactions/", handlers.GetTransactions)
|
||||
e.POST("/v3/transactions/", handlers.PostTransactions)
|
||||
|
||||
// Check bottin is ready
|
||||
|
||||
|
|
|
@ -4,12 +4,16 @@ import (
|
|||
"net/http"
|
||||
|
||||
"git.agecem.com/agecem/bottin-agenda/data"
|
||||
"git.agecem.com/agecem/bottin-agenda/responses"
|
||||
bottindata "git.agecem.com/agecem/bottin/v5/data"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func GetHealth(c echo.Context) error {
|
||||
var response responses.GetHealthResponse
|
||||
var statusCode int = http.StatusNotImplemented
|
||||
|
||||
bottinApiKey := viper.GetString("bottin.api.key")
|
||||
bottinApiHost := viper.GetString("bottin.api.host")
|
||||
bottinApiProtocol := viper.GetString("bottin.api.protocol")
|
||||
|
@ -48,9 +52,10 @@ func GetHealth(c echo.Context) error {
|
|||
}
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, map[string]string{
|
||||
"message": "Bottin-agenda API v2 is ready",
|
||||
"bottin": bottinStatus,
|
||||
"database": databaseStatus,
|
||||
})
|
||||
statusCode = http.StatusOK
|
||||
response.Message = "Bottin-agenda API v3 is ready"
|
||||
response.Data.Bottin = bottinStatus
|
||||
response.Data.Database = databaseStatus
|
||||
|
||||
return c.JSON(statusCode, response)
|
||||
}
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
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)
|
||||
}
|
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// GetTransactions lists transactions on GET /v2/transactions http/1.1
|
||||
// GetTransactions handles the listing of transactions
|
||||
func GetTransactions(c echo.Context) error {
|
||||
var statusCode int = http.StatusInternalServerError
|
||||
var response responses.GetTransactionsResponse
|
||||
|
@ -46,7 +46,7 @@ func GetTransactions(c echo.Context) error {
|
|||
return c.JSON(statusCode, response)
|
||||
}
|
||||
|
||||
// PostTransactions creates transactions on POST /v2/transactions http/1.1
|
||||
// PostTransactions handles the creation of transactions
|
||||
func PostTransactions(c echo.Context) error {
|
||||
var statusCode int = http.StatusInternalServerError
|
||||
var response responses.PostTransactionsResponse
|
||||
|
|
|
@ -2,22 +2,22 @@ package responses
|
|||
|
||||
import (
|
||||
"git.agecem.com/agecem/bottin-agenda/models"
|
||||
bottinmodels "git.agecem.com/agecem/bottin/v5/models"
|
||||
)
|
||||
|
||||
type GetHealthResponseData struct {
|
||||
Bottin string `json:"bottin"`
|
||||
Database string `json:"database"`
|
||||
}
|
||||
|
||||
type GetHealthResponse struct {
|
||||
Message string `json:"message"`
|
||||
Data GetHealthResponseData `json:"data"`
|
||||
}
|
||||
|
||||
type PostSeedResponse struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type GetMembreResponseData struct {
|
||||
Membre bottinmodels.Membre `json:"membre"`
|
||||
}
|
||||
|
||||
type GetMembreResponse struct {
|
||||
Message string `json:"message"`
|
||||
Data GetMembreResponseData `json:"data"`
|
||||
}
|
||||
|
||||
type PostTransactionsResponseData struct {
|
||||
Transactions []models.Transaction `json:"transactions"`
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue