Ajouter /v2/seed #4

Merged
vlbeaudoin merged 2 commits from feature/route-seed into main 2023-06-06 02:20:18 -04:00
2 changed files with 37 additions and 0 deletions
Showing only changes of commit 2c2f3de788 - Show all commits

View file

@ -55,6 +55,8 @@ var apiCmd = &cobra.Command{
// Routes
e.POST("/v2/seed/", handlers.PostSeed)
e.GET("/v2/health/", handlers.GetHealth)
e.GET("/v2/membres/:membre_id/", handlers.GetMembre)

35
handlers/seed.go Normal file
View file

@ -0,0 +1,35 @@
package handlers
import (
"fmt"
"net/http"
"git.agecem.com/agecem/bottin-agenda/data"
"git.agecem.com/agecem/bottin-agenda/responses"
"github.com/labstack/echo/v4"
)
func PostSeed(c echo.Context) error {
var response responses.PostSeedResponse
var statusCode int = http.StatusInternalServerError
client, err := data.NewDataClientFromViper()
if err != nil {
response.Message = fmt.Sprintf("Error during data.NewDataClientFromViper(): %s", err)
return c.JSON(statusCode, response)
}
_, err = client.Seed()
if err != nil {
response.Message = fmt.Sprintf("Error during client.Seed(): %s", err)
return c.JSON(statusCode, response)
}
response.Message = "Seed seems successful"
statusCode = http.StatusOK
return c.JSON(statusCode, response)
}