From d70b0643e894e2b278193bf501b9f1471e51d9cb Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Mon, 20 Nov 2023 15:54:19 -0500 Subject: [PATCH] =?UTF-8?q?refactor:=20d=C3=A9placer=20handler=20SeedPOST?= =?UTF-8?q?=20=C3=A0=20seed.go?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apihandler/apihandler.go | 28 ---------------------------- apihandler/seed.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 28 deletions(-) create mode 100644 apihandler/seed.go diff --git a/apihandler/apihandler.go b/apihandler/apihandler.go index c9684ce..0dac7db 100644 --- a/apihandler/apihandler.go +++ b/apihandler/apihandler.go @@ -5,7 +5,6 @@ import ( "sort" "codeberg.org/vlbeaudoin/pave" - "git.agecem.com/agecem/agecem-org/apiresponse" "git.agecem.com/agecem/agecem-org/config" "git.agecem.com/agecem/agecem-org/media" "github.com/labstack/echo/v4" @@ -26,30 +25,3 @@ func (h *V1Handler) V1GET(c echo.Context) error { sort.Slice(routes, func(i, j int) bool { return routes[i].Path < routes[j].Path }) return c.JSON(http.StatusOK, routes) } - -// V1SeedPOST créé des buckets dans minio selon la liste de buckets dans server.documents.buckets -// Les buckets sont créés avec paramètres par défaut, et sont ensuite visible dans /v1/bucket. -func (h *V1Handler) V1SeedPOST(c echo.Context) error { - var response apiresponse.V1SeedPOST - - new_buckets, err := h.MediaClient.Seed() - response.Data.Buckets = new_buckets - if err != nil { - response.StatusCode = http.StatusInternalServerError - response.Message = "Error during mediaClient.Seed()" - response.Error = err.Error() - - return c.JSON(response.StatusCode, response) - } - - if len(new_buckets) == 0 { - response.Message = "All buckets already exist" - - } else { - response.Message = "Buckets successfully created" - } - - response.StatusCode = http.StatusOK - - return c.JSON(response.StatusCode, response) -} diff --git a/apihandler/seed.go b/apihandler/seed.go new file mode 100644 index 0000000..77f93c6 --- /dev/null +++ b/apihandler/seed.go @@ -0,0 +1,35 @@ +package apihandler + +import ( + "net/http" + + "git.agecem.com/agecem/agecem-org/apiresponse" + "github.com/labstack/echo/v4" +) + +// V1SeedPOST créé des buckets dans minio selon la liste de buckets dans server.documents.buckets +// Les buckets sont créés avec paramètres par défaut, et sont ensuite visible dans /v1/bucket. +func (h *V1Handler) V1SeedPOST(c echo.Context) error { + var response apiresponse.V1SeedPOST + + new_buckets, err := h.MediaClient.Seed() + response.Data.Buckets = new_buckets + if err != nil { + response.StatusCode = http.StatusInternalServerError + response.Message = "Error during mediaClient.Seed()" + response.Error = err.Error() + + return c.JSON(response.StatusCode, response) + } + + if len(new_buckets) == 0 { + response.Message = "All buckets already exist" + + } else { + response.Message = "Buckets successfully created" + } + + response.StatusCode = http.StatusOK + + return c.JSON(response.StatusCode, response) +}