fix!: déplacer V1DocumentPOST.Data.Bucket à Params #177

Merged
vlbeaudoin merged 1 commit from fix/pave-json into main 2023-11-20 17:18:35 -05:00
2 changed files with 9 additions and 7 deletions
Showing only changes of commit 8054552054 - Show all commits

View file

@ -15,7 +15,7 @@ func (h *V1Handler) V1DocumentPOST(c echo.Context) (err error) {
var request apirequest.V1DocumentPOST
var response apiresponse.V1DocumentPOST
request.Data.Bucket = c.Param("bucket")
request.Params.Bucket = c.Param("bucket")
request.Data.Document, err = c.FormFile("document")
if err != nil {
@ -28,7 +28,7 @@ func (h *V1Handler) V1DocumentPOST(c echo.Context) (err error) {
allowed := false
for bucket_allowed := range h.Config.Server.Documents.Buckets {
if request.Data.Bucket == bucket_allowed {
if request.Params.Bucket == bucket_allowed {
allowed = true
}
}
@ -58,7 +58,7 @@ func (h *V1Handler) V1DocumentPOST(c echo.Context) (err error) {
}
defer src.Close()
info, err := h.MediaClient.MinioClient.PutObject(ctx, request.Data.Bucket, request.Data.Document.Filename, src, request.Data.Document.Size, minio.PutObjectOptions{
info, err := h.MediaClient.MinioClient.PutObject(ctx, request.Params.Bucket, request.Data.Document.Filename, src, request.Data.Document.Size, minio.PutObjectOptions{
ContentType: request.Data.Document.Header.Get("Content-Type"),
})
if err != nil {

View file

@ -16,9 +16,11 @@ var _ request.Requester[apiresponse.V1DocumentPOST] = V1DocumentPOST{}
type V1DocumentPOST struct {
Data struct {
Bucket string
Document *multipart.FileHeader
}
Params struct {
Bucket string
}
}
func NewV1DocumentPOST(bucket string, document *multipart.FileHeader) (request V1DocumentPOST, err error) {
@ -27,7 +29,7 @@ func NewV1DocumentPOST(bucket string, document *multipart.FileHeader) (request V
return
}
request.Data.Bucket = bucket
request.Params.Bucket = bucket
if document == nil {
err = fmt.Errorf("NewV1DocumentPOST requires non-nil document")
@ -40,7 +42,7 @@ func NewV1DocumentPOST(bucket string, document *multipart.FileHeader) (request V
}
func (request V1DocumentPOST) Complete() bool {
return request.Data.Bucket != "" && request.Data.Document != nil
return request.Params.Bucket != "" && request.Data.Document != nil
}
func (request V1DocumentPOST) Request(v *voki.Voki) (response apiresponse.V1DocumentPOST, err error) {
@ -54,7 +56,7 @@ func (request V1DocumentPOST) Request(v *voki.Voki) (response apiresponse.V1Docu
return
}
return response, v.UnmarshalIfComplete(http.MethodPost, fmt.Sprintf("/v1/bucket/%s", request.Data.Bucket), &buf, true, &response)
return response, v.UnmarshalIfComplete(http.MethodPost, fmt.Sprintf("/v1/bucket/%s", request.Params.Bucket), &buf, true, &response)
}
var _ request.Requester[apiresponse.V1DocumentDELETE] = V1DocumentDELETE{}