Skip to content

Commit

Permalink
feat: swagger + data -> file
Browse files Browse the repository at this point in the history
  • Loading branch information
bookpanda committed Jan 29, 2024
1 parent 2f63ddb commit ee9c4e6
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/app/dto/image.dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/handler/image/image.handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -58,7 +58,7 @@ func (h *Handler) Upload(c *router.FiberCtx) {

request := &dto.UploadImageRequest{
Filename: filename,
Data: file.Data,
File: file.Data,
PetId: petId,
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/utils/image/image.utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1492,11 +1492,11 @@ const docTemplate = `{
"dto.UploadImageRequest": {
"type": "object",
"required": [
"data",
"file",
"filename"
],
"properties": {
"data": {
"file": {
"type": "array",
"items": {
"type": "integer"
Expand Down
6 changes: 3 additions & 3 deletions src/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1488,11 +1488,11 @@
"dto.UploadImageRequest": {
"type": "object",
"required": [
"data",
"file",
"filename"
],
"properties": {
"data": {
"file": {
"type": "array",
"items": {
"type": "integer"
Expand Down
6 changes: 3 additions & 3 deletions src/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ definitions:
type: object
dto.UploadImageRequest:
properties:
data:
file:
items:
type: integer
type: array
Expand All @@ -375,7 +375,7 @@ definitions:
pet_id:
type: string
required:
- data
- file
- filename
type: object
dto.User:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit ee9c4e6

Please sign in to comment.