Merge pull request 'fix!: déplacer V1DocumentPOST.Data.Bucket à Params' (#177) from fix/pave-json into main

Reviewed-on: #177
This commit is contained in:
Victor Lacasse-Beaudoin 2023-11-20 17:18:34 -05:00
commit ba4558bb6d
2 changed files with 9 additions and 7 deletions

View file

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

View file

@ -16,9 +16,11 @@ var _ request.Requester[apiresponse.V1DocumentPOST] = V1DocumentPOST{}
type V1DocumentPOST struct { type V1DocumentPOST struct {
Data struct { Data struct {
Bucket string
Document *multipart.FileHeader Document *multipart.FileHeader
} }
Params struct {
Bucket string
}
} }
func NewV1DocumentPOST(bucket string, document *multipart.FileHeader) (request V1DocumentPOST, err error) { 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 return
} }
request.Data.Bucket = bucket request.Params.Bucket = bucket
if document == nil { if document == nil {
err = fmt.Errorf("NewV1DocumentPOST requires non-nil document") 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 { 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) { 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
} }
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{} var _ request.Requester[apiresponse.V1DocumentDELETE] = V1DocumentDELETE{}