Déplacer api responses vers apiresponse/
This commit is contained in:
parent
cb977f767d
commit
0962ea5a20
5 changed files with 42 additions and 29 deletions
|
@ -5,9 +5,9 @@ import (
|
|||
"net/http"
|
||||
"sort"
|
||||
|
||||
"git.agecem.com/agecem/agecem-org/apiresponse"
|
||||
"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"
|
||||
)
|
||||
|
@ -30,7 +30,7 @@ func (h *V1Handler) 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 (h *V1Handler) HandleV1Seed(c echo.Context) error {
|
||||
var response models.V1SeedResponse
|
||||
var response apiresponse.V1SeedResponse
|
||||
|
||||
new_buckets, err := h.MediaClient.Seed()
|
||||
response.Data.Buckets = new_buckets
|
||||
|
@ -56,7 +56,7 @@ func (h *V1Handler) HandleV1Seed(c echo.Context) error {
|
|||
|
||||
// HandleV1BucketList affiche les buckets permis par server.documents.buckets, qui existent.
|
||||
func (h *V1Handler) HandleV1BucketList(c echo.Context) error {
|
||||
var response models.V1BucketListResponse
|
||||
var response apiresponse.V1BucketListResponse
|
||||
|
||||
var buckets = make(map[string]string)
|
||||
|
||||
|
@ -83,7 +83,7 @@ func (h *V1Handler) HandleV1BucketList(c echo.Context) error {
|
|||
}
|
||||
|
||||
func (h *V1Handler) HandleV1BucketRead(c echo.Context) error {
|
||||
var response models.V1BucketReadResponse
|
||||
var response apiresponse.V1BucketReadResponse
|
||||
|
||||
bucket := c.Param("bucket")
|
||||
|
||||
|
@ -95,7 +95,7 @@ func (h *V1Handler) HandleV1BucketRead(c echo.Context) error {
|
|||
}
|
||||
|
||||
if !allowed {
|
||||
return c.JSON(models.NotFoundResponse())
|
||||
return c.JSON(apiresponse.NotFoundResponse())
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
@ -112,7 +112,7 @@ func (h *V1Handler) HandleV1BucketRead(c echo.Context) error {
|
|||
}
|
||||
|
||||
if !exists {
|
||||
return c.JSON(models.NotFoundResponse())
|
||||
return c.JSON(apiresponse.NotFoundResponse())
|
||||
}
|
||||
|
||||
objectCh := h.MediaClient.MinioClient.ListObjects(ctx, bucket, minio.ListObjectsOptions{})
|
||||
|
@ -137,7 +137,7 @@ func (h *V1Handler) HandleV1BucketRead(c echo.Context) error {
|
|||
|
||||
// HandleV1DocumentCreate permet d'ajouter un object dans un bucket, par multipart/form-data
|
||||
func (h *V1Handler) HandleV1DocumentCreate(c echo.Context) error {
|
||||
var response models.V1DocumentCreateResponse
|
||||
var response apiresponse.V1DocumentCreateResponse
|
||||
|
||||
bucket := c.Param("bucket")
|
||||
|
||||
|
@ -158,7 +158,7 @@ func (h *V1Handler) HandleV1DocumentCreate(c echo.Context) error {
|
|||
}
|
||||
|
||||
if !allowed {
|
||||
return c.JSON(models.NotFoundResponse())
|
||||
return c.JSON(apiresponse.NotFoundResponse())
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
@ -208,7 +208,7 @@ func (h *V1Handler) HandleV1DocumentRead(c echo.Context) error {
|
|||
}
|
||||
|
||||
if !allowed {
|
||||
return c.JSON(models.NotFoundResponse())
|
||||
return c.JSON(apiresponse.NotFoundResponse())
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
@ -221,7 +221,7 @@ func (h *V1Handler) HandleV1DocumentRead(c echo.Context) error {
|
|||
}
|
||||
|
||||
if !bucket_exists {
|
||||
return c.JSON(models.NotFoundResponse())
|
||||
return c.JSON(apiresponse.NotFoundResponse())
|
||||
}
|
||||
|
||||
document_info, err := h.MediaClient.MinioClient.StatObject(ctx, bucket, document, minio.StatObjectOptions{})
|
||||
|
@ -229,7 +229,7 @@ func (h *V1Handler) HandleV1DocumentRead(c echo.Context) error {
|
|||
if err != nil {
|
||||
if err.Error() == "The specified key does not exist." {
|
||||
|
||||
return c.JSON(models.NotFoundResponse())
|
||||
return c.JSON(apiresponse.NotFoundResponse())
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusInternalServerError, map[string]interface{}{
|
||||
|
@ -253,7 +253,7 @@ func (h *V1Handler) HandleV1DocumentRead(c echo.Context) error {
|
|||
|
||||
// HandleV1DocumentUpdate permet de mettre à jour certains champs d'un object, comme le Content-Type ou le Filename
|
||||
func (h *V1Handler) HandleV1DocumentUpdate(c echo.Context) error {
|
||||
return c.JSON(models.NotImplementedResponse())
|
||||
return c.JSON(apiresponse.NotImplementedResponse())
|
||||
}
|
||||
|
||||
// HandleV1DocumentDelete permet de supprimer un object
|
||||
|
@ -269,7 +269,7 @@ func (h *V1Handler) HandleV1DocumentDelete(c echo.Context) error {
|
|||
}
|
||||
|
||||
if !allowed {
|
||||
return c.JSON(models.NotFoundResponse())
|
||||
return c.JSON(apiresponse.NotFoundResponse())
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
@ -282,14 +282,14 @@ func (h *V1Handler) HandleV1DocumentDelete(c echo.Context) error {
|
|||
}
|
||||
|
||||
if !bucket_exists {
|
||||
return c.JSON(models.NotFoundResponse())
|
||||
return c.JSON(apiresponse.NotFoundResponse())
|
||||
}
|
||||
|
||||
document_info, err := h.MediaClient.MinioClient.StatObject(ctx, bucket, document, minio.StatObjectOptions{})
|
||||
if err != nil {
|
||||
if err.Error() == "The specified key does not exist." {
|
||||
|
||||
return c.JSON(models.NotFoundResponse())
|
||||
return c.JSON(apiresponse.NotFoundResponse())
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusInternalServerError, map[string]interface{}{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue