From ee9c4e651ca9aa32904df34f69ae65655c0bf054 Mon Sep 17 00:00:00 2001 From: Idhibhat Pankam Date: Tue, 30 Jan 2024 00:09:29 +0700 Subject: [PATCH] feat: swagger + data -> file --- src/app/dto/image.dto.go | 2 +- src/app/handler/image/image.handler.go | 4 ++-- src/app/utils/image/image.utils.go | 2 +- src/docs/docs.go | 6 +++--- src/docs/swagger.json | 6 +++--- src/docs/swagger.yaml | 6 +++--- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/app/dto/image.dto.go b/src/app/dto/image.dto.go index 5ecaf4d..d07bdbe 100644 --- a/src/app/dto/image.dto.go +++ b/src/app/dto/image.dto.go @@ -13,7 +13,7 @@ type ImageResponse struct { type UploadImageRequest struct { Filename string `json:"filename" validate:"required"` - Data []byte `json:"data" validate:"required"` + File []byte `json:"file" validate:"required"` PetId string `json:"pet_id"` } diff --git a/src/app/handler/image/image.handler.go b/src/app/handler/image/image.handler.go index ec7f163..e904405 100644 --- a/src/app/handler/image/image.handler.go +++ b/src/app/handler/image/image.handler.go @@ -31,7 +31,7 @@ func NewHandler(service imageSvc.Service, validate validator.IDtoValidator, maxF // @Description Returns the data of image. If updating pet, add petId. If creating pet, petId is not specified, but keep the imageId. // @Param image body dto.UploadImageRequest true "upload image request dto" // @Tags image -// @Accept json +// @Accept multipart/form-data // @Produce json // @Success 201 {object} dto.ImageResponse // @Failure 400 {object} dto.ResponseBadRequestErr "Invalid request body" @@ -58,7 +58,7 @@ func (h *Handler) Upload(c *router.FiberCtx) { request := &dto.UploadImageRequest{ Filename: filename, - Data: file.Data, + File: file.Data, PetId: petId, } diff --git a/src/app/utils/image/image.utils.go b/src/app/utils/image/image.utils.go index 705c34f..620a830 100644 --- a/src/app/utils/image/image.utils.go +++ b/src/app/utils/image/image.utils.go @@ -30,7 +30,7 @@ func ProtoToDtoList(in []*imageProto.Image) []*dto.ImageResponse { func CreateDtoToProto(in *dto.UploadImageRequest) *imageProto.UploadImageRequest { return &imageProto.UploadImageRequest{ Filename: in.Filename, - Data: in.Data, + Data: in.File, PetId: in.PetId, } } diff --git a/src/docs/docs.go b/src/docs/docs.go index 505e88b..8e9ba2f 100644 --- a/src/docs/docs.go +++ b/src/docs/docs.go @@ -341,7 +341,7 @@ const docTemplate = `{ "post": { "description": "Returns the data of image. If updating pet, add petId. If creating pet, petId is not specified, but keep the imageId.", "consumes": [ - "application/json" + "multipart/form-data" ], "produces": [ "application/json" @@ -1492,11 +1492,11 @@ const docTemplate = `{ "dto.UploadImageRequest": { "type": "object", "required": [ - "data", + "file", "filename" ], "properties": { - "data": { + "file": { "type": "array", "items": { "type": "integer" diff --git a/src/docs/swagger.json b/src/docs/swagger.json index 3c1927f..1350d3d 100644 --- a/src/docs/swagger.json +++ b/src/docs/swagger.json @@ -337,7 +337,7 @@ "post": { "description": "Returns the data of image. If updating pet, add petId. If creating pet, petId is not specified, but keep the imageId.", "consumes": [ - "application/json" + "multipart/form-data" ], "produces": [ "application/json" @@ -1488,11 +1488,11 @@ "dto.UploadImageRequest": { "type": "object", "required": [ - "data", + "file", "filename" ], "properties": { - "data": { + "file": { "type": "array", "items": { "type": "integer" diff --git a/src/docs/swagger.yaml b/src/docs/swagger.yaml index 0a6164f..8c9baca 100644 --- a/src/docs/swagger.yaml +++ b/src/docs/swagger.yaml @@ -366,7 +366,7 @@ definitions: type: object dto.UploadImageRequest: properties: - data: + file: items: type: integer type: array @@ -375,7 +375,7 @@ definitions: pet_id: type: string required: - - data + - file - filename type: object dto.User: @@ -626,7 +626,7 @@ paths: /v1/images: post: consumes: - - application/json + - multipart/form-data description: Returns the data of image. If updating pet, add petId. If creating pet, petId is not specified, but keep the imageId. parameters: