Implémenter HandleV1BucketListResponse

This commit is contained in:
Victor Lacasse-Beaudoin 2023-08-20 17:57:14 -04:00
parent c8af2acae9
commit d736d53a43

View file

@ -61,19 +61,24 @@ func HandleV1Seed(c echo.Context) error {
// HandleV1BucketList affiche les buckets permis par server.documents.buckets, qui existent. // HandleV1BucketList affiche les buckets permis par server.documents.buckets, qui existent.
func HandleV1BucketList(c echo.Context) error { func HandleV1BucketList(c echo.Context) error {
var response models.V1BucketListResponse
var cfg config.Config var cfg config.Config
if err := viper.Unmarshal(&cfg); err != nil { if err := viper.Unmarshal(&cfg); err != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{ response.StatusCode = http.StatusInternalServerError
"error": err.Error(), response.Message = "Error during viper.Unmarshal"
}) // response.Error = err.Error()
return c.JSON(response.StatusCode, response)
} }
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)
} }
var buckets = make(map[string]string) var buckets = make(map[string]string)
@ -81,7 +86,11 @@ func HandleV1BucketList(c echo.Context) error {
for bucket_name, bucket_display_name := range cfg.Server.Documents.Buckets { for bucket_name, bucket_display_name := range cfg.Server.Documents.Buckets {
exists, err := mediaClient.MinioClient.BucketExists(context.Background(), bucket_name) exists, err := mediaClient.MinioClient.BucketExists(context.Background(), bucket_name)
if err != nil { if err != nil {
return c.JSON(http.StatusInternalServerError, "Error during minio#BucketExists") response.StatusCode = http.StatusInternalServerError
response.Message = "Error during minio#BucketExists"
// response.Error = err.Error()
return c.JSON(response.StatusCode, response)
} }
if exists { if exists {
@ -89,7 +98,12 @@ func HandleV1BucketList(c echo.Context) error {
} }
} }
return c.JSON(http.StatusOK, buckets) response.StatusCode = http.StatusOK
response.Message = "Buckets list successful"
response.Data.Buckets = buckets
return c.JSON(response.StatusCode, response)
//return c.JSON(response.StatusCode, response.Data.Buckets)
} }
func HandleV1BucketRead(c echo.Context) error { func HandleV1BucketRead(c echo.Context) error {