feat: pave V1DocumentDELETE
This commit is contained in:
parent
c7282edcc2
commit
86f1284e12
4 changed files with 83 additions and 16 deletions
|
@ -141,12 +141,15 @@ func (h *V1Handler) V1DocumentPUT(c echo.Context) error {
|
|||
|
||||
// V1DocumentDELETE permet de supprimer un object
|
||||
func (h *V1Handler) V1DocumentDELETE(c echo.Context) error {
|
||||
bucket := c.Param("bucket")
|
||||
document := c.Param("document")
|
||||
var request apirequest.V1DocumentDELETE
|
||||
var response apiresponse.V1DocumentDELETE
|
||||
|
||||
request.Params.Bucket = c.Param("bucket")
|
||||
request.Params.Document = c.Param("document")
|
||||
|
||||
allowed := false
|
||||
for bucket_allowed := range h.Config.Server.Documents.Buckets {
|
||||
if bucket == bucket_allowed {
|
||||
if request.Params.Bucket == bucket_allowed {
|
||||
allowed = true
|
||||
}
|
||||
}
|
||||
|
@ -155,11 +158,18 @@ func (h *V1Handler) V1DocumentDELETE(c echo.Context) error {
|
|||
return c.JSON(apiresponse.NotFoundResponse())
|
||||
}
|
||||
|
||||
if !request.Complete() {
|
||||
response.Message = "Incomplete V1DocumentDELETE request received"
|
||||
response.StatusCode = http.StatusBadRequest
|
||||
|
||||
return c.JSON(response.StatusCode, response)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
defer cancel()
|
||||
|
||||
bucket_exists, err := h.MediaClient.MinioClient.BucketExists(ctx, bucket)
|
||||
bucket_exists, err := h.MediaClient.MinioClient.BucketExists(ctx, request.Params.Bucket)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, "Error during minio#BucketExists")
|
||||
}
|
||||
|
@ -168,29 +178,34 @@ func (h *V1Handler) V1DocumentDELETE(c echo.Context) error {
|
|||
return c.JSON(apiresponse.NotFoundResponse())
|
||||
}
|
||||
|
||||
document_info, err := h.MediaClient.MinioClient.StatObject(ctx, bucket, document, minio.StatObjectOptions{})
|
||||
document_info, err := h.MediaClient.MinioClient.StatObject(ctx, request.Params.Bucket, request.Params.Document, minio.StatObjectOptions{})
|
||||
if err != nil {
|
||||
if err.Error() == "The specified key does not exist." {
|
||||
|
||||
return c.JSON(apiresponse.NotFoundResponse())
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusInternalServerError, map[string]interface{}{
|
||||
"message": "Error during minio#StatObject",
|
||||
})
|
||||
//response.Error = err.Error()
|
||||
response.Message = "Error during minio#StatObject"
|
||||
response.StatusCode = http.StatusInternalServerError
|
||||
|
||||
return c.JSON(response.StatusCode, response)
|
||||
}
|
||||
|
||||
//TODO Add error validation
|
||||
_ = document_info
|
||||
|
||||
err = h.MediaClient.MinioClient.RemoveObject(ctx, bucket, document, minio.RemoveObjectOptions{})
|
||||
err = h.MediaClient.MinioClient.RemoveObject(ctx, request.Params.Bucket, request.Params.Document, minio.RemoveObjectOptions{})
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, map[string]string{
|
||||
"message": "Error during minio#RemoveObject",
|
||||
})
|
||||
//response.Error = err.Error()
|
||||
response.Message = "Error during minio#RemoveObject"
|
||||
response.StatusCode = http.StatusInternalServerError
|
||||
|
||||
return c.JSON(response.StatusCode, response)
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, map[string]string{
|
||||
"message": "Document deleted",
|
||||
})
|
||||
response.Message = "Document deleted"
|
||||
response.StatusCode = http.StatusOK
|
||||
|
||||
return c.JSON(response.StatusCode, response)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue