From 8dd0049fbad31153895052ed12416853083a3958 Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Sat, 19 Aug 2023 19:58:09 -0400 Subject: [PATCH] =?UTF-8?q?Mettre=20=C3=A0=20jour=20utilisation=20de=20mod?= =?UTF-8?q?els.Bucket=20et=20V1SeedResponse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/server.go | 4 ++-- serverhandlers/serverhandlers.go | 34 ++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/cmd/server.go b/cmd/server.go index 5e4f8a4..556c477 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -444,7 +444,7 @@ func handleAdminDocumentsUploadPOST(c echo.Context) error { } for bucketName, displayName := range buckets { - data.Buckets = append(data.Buckets, Bucket{ + data.Buckets = append(data.Buckets, models.Bucket{ Name: bucketName, DisplayName: displayName, }) @@ -467,7 +467,7 @@ func handleAdminDocumentsUploadPOST(c echo.Context) error { // Format response var info, status string - info = fmt.Sprintf("[%.0f] /public/documentation/%s/%s", response.Info.Size, response.Info.Bucket, response.Info.Object) + info = fmt.Sprintf("[%.0f] /public/documentation/%s/%s", response.Data.Size, response.Data.Bucket, response.Data.Object) status = response.Message diff --git a/serverhandlers/serverhandlers.go b/serverhandlers/serverhandlers.go index 6aca6d1..e7c8e1f 100644 --- a/serverhandlers/serverhandlers.go +++ b/serverhandlers/serverhandlers.go @@ -7,6 +7,7 @@ import ( "git.agecem.com/agecem/agecem-org/config" "git.agecem.com/agecem/agecem-org/media" + "git.agecem.com/agecem/agecem-org/models" "github.com/labstack/echo/v4" "github.com/minio/minio-go/v7" "github.com/spf13/viper" @@ -25,34 +26,37 @@ func HandleV1(c echo.Context) error { // HandleV1Seed 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 HandleV1Seed(c echo.Context) error { + var response models.V1SeedResponse + mediaClient, err := media.NewMediaClientFromViper() if err != nil { - return c.JSON(http.StatusInternalServerError, map[string]string{ - "message": "Error during media.NewMediaClientFromViper()", - "error": err.Error(), - }) + response.StatusCode = http.StatusInternalServerError + response.Message = "Error during media.NewMediaClientFromViper()" + response.Error = err.Error() + + return c.JSON(response.StatusCode, response) } new_buckets, err := mediaClient.Seed() + response.Data.Buckets = new_buckets if err != nil { - return c.JSON(http.StatusInternalServerError, map[string]string{ - "message": "Error during mediaClient.Seed()", - "error": err.Error(), - }) + response.StatusCode = http.StatusInternalServerError + response.Message = "Error during mediaClient.Seed()" + response.Error = err.Error() + + return c.JSON(response.StatusCode, response) } - var message string if len(new_buckets) == 0 { - message = "All buckets already exist" + response.Message = "All buckets already exist" } else { - message = "Buckets successfully created" + response.Message = "Buckets successfully created" } - return c.JSON(http.StatusOK, map[string]interface{}{ - "message": message, - "buckets": new_buckets, - }) + response.StatusCode = http.StatusOK + + return c.JSON(response.StatusCode, response) } // HandleV1BucketList affiche les buckets permis par server.documents.buckets, qui existent.