wip: ajouter handler V1DocumentsPOST
Contient déjà la plupart de la logique autour de `mediaclient.(*MediaClient).UploadFormFiles`
This commit is contained in:
parent
24855a4115
commit
d3ad8f4a91
1 changed files with 46 additions and 0 deletions
|
@ -2,6 +2,7 @@ package apihandler
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"git.agecem.com/agecem/agecem-org/apirequest"
|
||||
|
@ -10,6 +11,51 @@ import (
|
|||
"github.com/minio/minio-go/v7"
|
||||
)
|
||||
|
||||
/*
|
||||
V1DocumentPOST permet d'ajouter un object dans un bucket, par multipart/form-data
|
||||
|
||||
WIP
|
||||
*/
|
||||
func (h *V1Handler) V1DocumentsPOST(c echo.Context) (err error) {
|
||||
var request apirequest.V1DocumentsPOST
|
||||
var response apiresponse.V1DocumentsPOST
|
||||
|
||||
request.Params.Bucket = c.Param("bucket")
|
||||
|
||||
form, err := c.MultipartForm()
|
||||
if err != nil {
|
||||
response.StatusCode = http.StatusBadRequest
|
||||
response.Message = fmt.Sprintf("Téléversement invalide: %s", err)
|
||||
|
||||
return c.JSON(response.StatusCode, response)
|
||||
}
|
||||
if form == nil {
|
||||
return c.JSON(http.StatusBadRequest, "MultipartForm pointer vers une addresse mémoire nil")
|
||||
}
|
||||
|
||||
if len(form.File) == 0 {
|
||||
return c.JSON(http.StatusBadRequest, "Veuillez sélectionner au moins 1 document à téléverser")
|
||||
}
|
||||
|
||||
for inputName, inputFileHeaders := range form.File {
|
||||
if inputName == "documents" {
|
||||
request.Data.Documents = inputFileHeaders
|
||||
}
|
||||
}
|
||||
|
||||
if request.Data.Documents == nil {
|
||||
return c.JSON(http.StatusBadRequest, "Impossible d'obtenir les documents depuis le formulaire")
|
||||
}
|
||||
|
||||
if !request.Complete() {
|
||||
return c.JSON(http.StatusBadRequest, "Requête V1DocumentsPOST incomplète reçue")
|
||||
}
|
||||
|
||||
response.StatusCode, response.Message = h.MediaClient.UploadFormFiles(request.Data.Documents)
|
||||
|
||||
return c.JSON(response.StatusCode, response.Message)
|
||||
}
|
||||
|
||||
// V1DocumentPOST permet d'ajouter un object dans un bucket, par multipart/form-data
|
||||
func (h *V1Handler) V1DocumentPOST(c echo.Context) (err error) {
|
||||
var request apirequest.V1DocumentPOST
|
||||
|
|
Loading…
Reference in a new issue