Ajouter models/ pour type Bucket #109

Merged
vlbeaudoin merged 8 commits from refactor/models into main 2023-08-19 20:31:38 -04:00
2 changed files with 21 additions and 17 deletions
Showing only changes of commit 8dd0049fba - Show all commits

View file

@ -444,7 +444,7 @@ func handleAdminDocumentsUploadPOST(c echo.Context) error {
} }
for bucketName, displayName := range buckets { for bucketName, displayName := range buckets {
data.Buckets = append(data.Buckets, Bucket{ data.Buckets = append(data.Buckets, models.Bucket{
Name: bucketName, Name: bucketName,
DisplayName: displayName, DisplayName: displayName,
}) })
@ -467,7 +467,7 @@ func handleAdminDocumentsUploadPOST(c echo.Context) error {
// Format response // Format response
var info, status string 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 status = response.Message

View file

@ -7,6 +7,7 @@ import (
"git.agecem.com/agecem/agecem-org/config" "git.agecem.com/agecem/agecem-org/config"
"git.agecem.com/agecem/agecem-org/media" "git.agecem.com/agecem/agecem-org/media"
"git.agecem.com/agecem/agecem-org/models"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7"
"github.com/spf13/viper" "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 // 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. // Les buckets sont créés avec paramètres par défaut, et sont ensuite visible dans /v1/bucket.
func HandleV1Seed(c echo.Context) error { func HandleV1Seed(c echo.Context) error {
var response models.V1SeedResponse
mediaClient, err := media.NewMediaClientFromViper() mediaClient, err := media.NewMediaClientFromViper()
if err != nil { if err != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{ response.StatusCode = http.StatusInternalServerError
"message": "Error during media.NewMediaClientFromViper()", response.Message = "Error during media.NewMediaClientFromViper()"
"error": err.Error(), response.Error = err.Error()
})
return c.JSON(response.StatusCode, response)
} }
new_buckets, err := mediaClient.Seed() new_buckets, err := mediaClient.Seed()
response.Data.Buckets = new_buckets
if err != nil { if err != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{ response.StatusCode = http.StatusInternalServerError
"message": "Error during mediaClient.Seed()", response.Message = "Error during mediaClient.Seed()"
"error": err.Error(), response.Error = err.Error()
})
return c.JSON(response.StatusCode, response)
} }
var message string
if len(new_buckets) == 0 { if len(new_buckets) == 0 {
message = "All buckets already exist" response.Message = "All buckets already exist"
} else { } else {
message = "Buckets successfully created" response.Message = "Buckets successfully created"
} }
return c.JSON(http.StatusOK, map[string]interface{}{ response.StatusCode = http.StatusOK
"message": message,
"buckets": new_buckets, return c.JSON(response.StatusCode, response)
})
} }
// HandleV1BucketList affiche les buckets permis par server.documents.buckets, qui existent. // HandleV1BucketList affiche les buckets permis par server.documents.buckets, qui existent.