From 20d5b3ad3313f60d414b24bb6953da625dba8680 Mon Sep 17 00:00:00 2001 From: Gear <84141000+macgeargear@users.noreply.github.com> Date: Mon, 8 Jan 2024 09:49:45 +0700 Subject: [PATCH 1/7] docs: add like end point --- src/docs/docs.go | 610 +++++++++++++++++++++++++++++++++++++++++- src/docs/swagger.json | 610 +++++++++++++++++++++++++++++++++++++++++- src/docs/swagger.yaml | 413 +++++++++++++++++++++++++++- 3 files changed, 1600 insertions(+), 33 deletions(-) diff --git a/src/docs/docs.go b/src/docs/docs.go index de72062..37f6e1b 100644 --- a/src/docs/docs.go +++ b/src/docs/docs.go @@ -234,7 +234,155 @@ const docTemplate = `{ } } }, - "/v1/pet/": { + "/v1/likes/": { + "get": { + "description": "Return dto.ResponseSuccess", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "like" + ], + "summary": "find likes by user id", + "parameters": [ + { + "type": "string", + "description": "user id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/dto.ResponseSuccess" + } + }, + "404": { + "description": "user not found", + "schema": { + "$ref": "#/definitions/dto.ResponseNotfoundErr" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/dto.ResponseInternalErr" + } + }, + "503": { + "description": "Service is down", + "schema": { + "$ref": "#/definitions/dto.ResponseServiceDownErr" + } + } + } + }, + "post": { + "description": "Return dto.ResponseSuccess", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "like" + ], + "summary": "create like", + "parameters": [ + { + "description": "create like request", + "name": "create", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/dto.CreateLikeRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/dto.ResponseSuccess" + } + }, + "400": { + "description": "Invalid request body", + "schema": { + "$ref": "#/definitions/dto.ResponseBadRequestErr" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/dto.ResponseInternalErr" + } + }, + "503": { + "description": "Service is down", + "schema": { + "$ref": "#/definitions/dto.ResponseServiceDownErr" + } + } + } + }, + "delete": { + "description": "Return dto.ResponseSuccess if like is successfully deleted", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "like" + ], + "summary": "delete like", + "parameters": [ + { + "type": "string", + "description": "user id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/dto.ResponseSuccess" + } + }, + "404": { + "description": "like not found", + "schema": { + "$ref": "#/definitions/dto.ResponseNotfoundErr" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/dto.ResponseInternalErr" + } + }, + "503": { + "description": "Service is down", + "schema": { + "$ref": "#/definitions/dto.ResponseServiceDownErr" + } + } + } + } + }, + "/v1/pets/": { "get": { "description": "Return the data of pets if successfully", "consumes": [ @@ -244,17 +392,163 @@ const docTemplate = `{ "application/json" ], "tags": [ - "auth" + "pet" ], "summary": "find all pets", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/dto.ResponseSuccess" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/dto.ResponseInternalErr" + } + }, + "503": { + "description": "Service is down", + "schema": { + "$ref": "#/definitions/dto.ResponseServiceDownErr" + } + } + } + }, + "put": { + "description": "Return the status true of pet if successfully else false", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "pet" + ], + "summary": "change view pet", + "parameters": [ + { + "description": "change view pet dto", + "name": "changeView", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/dto.ChangeViewPetRequest" + } + }, + { + "type": "string", + "description": "pet id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/dto.ResponseSuccess" + } + }, + "400": { + "description": "Invalid request body", + "schema": { + "$ref": "#/definitions/dto.ResponseBadRequestErr" + } + }, + "404": { + "description": "Pet not found", + "schema": { + "$ref": "#/definitions/dto.ResponseNotfoundErr" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/dto.ResponseInternalErr" + } + }, + "503": { + "description": "Service is down", + "schema": { + "$ref": "#/definitions/dto.ResponseServiceDownErr" + } + } + } + }, + "delete": { + "description": "Return the status true of pet if successfully else false", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "pet" + ], + "summary": "delete pet", + "parameters": [ + { + "type": "string", + "description": "pet id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/dto.ResponseSuccess" + } + }, + "400": { + "description": "Invalid request body", + "schema": { + "$ref": "#/definitions/dto.ResponseBadRequestErr" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/dto.ResponseInternalErr" + } + }, + "503": { + "description": "Service is down", + "schema": { + "$ref": "#/definitions/dto.ResponseServiceDownErr" + } + } + } + } + }, + "/v1/pets/create": { + "post": { + "description": "Return the data of pet if successfully", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "pet" + ], + "summary": "create pet", "parameters": [ { "description": "pet dto", - "name": "signup", + "name": "create", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/dto.PetDto" + "$ref": "#/definitions/dto.CreatePetRequest" } } ], @@ -262,7 +556,7 @@ const docTemplate = `{ "201": { "description": "Created", "schema": { - "$ref": "#/definitions/dto.PetDto" + "$ref": "#/definitions/dto.ResponseSuccess" } }, "400": { @@ -271,10 +565,191 @@ const docTemplate = `{ "$ref": "#/definitions/dto.ResponseBadRequestErr" } }, - "409": { - "description": "Duplicate email", + "500": { + "description": "Internal service error", "schema": { - "$ref": "#/definitions/dto.ResponseConflictErr" + "$ref": "#/definitions/dto.ResponseInternalErr" + } + }, + "503": { + "description": "Service is down", + "schema": { + "$ref": "#/definitions/dto.ResponseServiceDownErr" + } + } + } + } + }, + "/v1/pets/{id}": { + "get": { + "description": "Return the data of pets if successfully", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "auth" + ], + "summary": "find one pet", + "parameters": [ + { + "type": "string", + "description": "pet id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/dto.ResponseSuccess" + } + }, + "404": { + "description": "Pet not found", + "schema": { + "$ref": "#/definitions/dto.ResponseNotfoundErr" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/dto.ResponseInternalErr" + } + }, + "503": { + "description": "Service is down", + "schema": { + "$ref": "#/definitions/dto.ResponseServiceDownErr" + } + } + } + }, + "put": { + "description": "Return the data of pet if successfully", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "pet" + ], + "summary": "update pet", + "parameters": [ + { + "description": "update pet dto", + "name": "update", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/dto.UpdatePetRequest" + } + }, + { + "type": "string", + "description": "pet id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/dto.ResponseSuccess" + } + }, + "400": { + "description": "Invalid request body", + "schema": { + "$ref": "#/definitions/dto.ResponseBadRequestErr" + } + }, + "404": { + "description": "Pet not found", + "schema": { + "$ref": "#/definitions/dto.ResponseNotfoundErr" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/dto.ResponseInternalErr" + } + }, + "503": { + "description": "Service is down", + "schema": { + "$ref": "#/definitions/dto.ResponseServiceDownErr" + } + } + } + } + }, + "/v1/pets/{id}/adopt": { + "put": { + "description": "Return true if the pet is successfully adopted", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "pet" + ], + "summary": "Adopt a pet", + "parameters": [ + { + "type": "string", + "description": "Pet ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "User ID", + "name": "user_id", + "in": "body", + "required": true, + "schema": { + "type": "string" + } + }, + { + "description": "Pet ID", + "name": "pet_id", + "in": "body", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/dto.ResponseSuccess" + } + }, + "400": { + "description": "Invalid request body", + "schema": { + "$ref": "#/definitions/dto.ResponseBadRequestErr" + } + }, + "404": { + "description": "Pet not found", + "schema": { + "$ref": "#/definitions/dto.ResponseNotfoundErr" } }, "500": { @@ -306,6 +781,35 @@ const docTemplate = `{ "value": {} } }, + "dto.ChangeViewPetRequest": { + "type": "object", + "required": [ + "visible" + ], + "properties": { + "visible": { + "type": "boolean" + } + } + }, + "dto.CreateLikeRequest": { + "type": "object", + "required": [ + "pet_id", + "user_id" + ], + "properties": { + "pet_id": { + "type": "string" + }, + "user_id": { + "type": "string" + } + } + }, + "dto.CreatePetRequest": { + "type": "object" + }, "dto.Credential": { "type": "object", "properties": { @@ -334,9 +838,6 @@ const docTemplate = `{ } } }, - "dto.PetDto": { - "type": "object" - }, "dto.ResponseBadRequestErr": { "type": "object", "properties": { @@ -398,6 +899,20 @@ const docTemplate = `{ } } }, + "dto.ResponseNotfoundErr": { + "type": "object", + "properties": { + "data": {}, + "message": { + "type": "string", + "example": "Not found" + }, + "status_code": { + "type": "integer", + "example": 404 + } + } + }, "dto.ResponseServiceDownErr": { "type": "object", "properties": { @@ -412,6 +927,20 @@ const docTemplate = `{ } } }, + "dto.ResponseSuccess": { + "type": "object", + "properties": { + "data": {}, + "message": { + "type": "string", + "example": "success" + }, + "status_code": { + "type": "integer", + "example": 200 + } + } + }, "dto.ResponseUnauthorizedErr": { "type": "object", "properties": { @@ -492,6 +1021,65 @@ const docTemplate = `{ "type": "string" } } + }, + "dto.UpdatePetRequest": { + "type": "object", + "properties": { + "address": { + "type": "string" + }, + "adopt_by": { + "type": "string" + }, + "background": { + "type": "string" + }, + "birthdate": { + "type": "string" + }, + "caption": { + "type": "string" + }, + "contact": { + "type": "string" + }, + "gender": { + "type": "integer" + }, + "habit": { + "type": "string" + }, + "images": { + "type": "array", + "items": { + "type": "string" + } + }, + "is_club_pet": { + "type": "boolean" + }, + "is_sterile": { + "type": "boolean" + }, + "is_vaccinated": { + "type": "boolean" + }, + "is_visible": { + "type": "boolean" + }, + "name": { + "type": "string" + }, + "species": { + "type": "string" + }, + "status": { + "type": "integer" + }, + "type": { + "type": "string" + } + } } }, "securityDefinitions": { diff --git a/src/docs/swagger.json b/src/docs/swagger.json index 1303f34..3246ea6 100644 --- a/src/docs/swagger.json +++ b/src/docs/swagger.json @@ -229,7 +229,155 @@ } } }, - "/v1/pet/": { + "/v1/likes/": { + "get": { + "description": "Return dto.ResponseSuccess", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "like" + ], + "summary": "find likes by user id", + "parameters": [ + { + "type": "string", + "description": "user id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/dto.ResponseSuccess" + } + }, + "404": { + "description": "user not found", + "schema": { + "$ref": "#/definitions/dto.ResponseNotfoundErr" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/dto.ResponseInternalErr" + } + }, + "503": { + "description": "Service is down", + "schema": { + "$ref": "#/definitions/dto.ResponseServiceDownErr" + } + } + } + }, + "post": { + "description": "Return dto.ResponseSuccess", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "like" + ], + "summary": "create like", + "parameters": [ + { + "description": "create like request", + "name": "create", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/dto.CreateLikeRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/dto.ResponseSuccess" + } + }, + "400": { + "description": "Invalid request body", + "schema": { + "$ref": "#/definitions/dto.ResponseBadRequestErr" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/dto.ResponseInternalErr" + } + }, + "503": { + "description": "Service is down", + "schema": { + "$ref": "#/definitions/dto.ResponseServiceDownErr" + } + } + } + }, + "delete": { + "description": "Return dto.ResponseSuccess if like is successfully deleted", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "like" + ], + "summary": "delete like", + "parameters": [ + { + "type": "string", + "description": "user id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/dto.ResponseSuccess" + } + }, + "404": { + "description": "like not found", + "schema": { + "$ref": "#/definitions/dto.ResponseNotfoundErr" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/dto.ResponseInternalErr" + } + }, + "503": { + "description": "Service is down", + "schema": { + "$ref": "#/definitions/dto.ResponseServiceDownErr" + } + } + } + } + }, + "/v1/pets/": { "get": { "description": "Return the data of pets if successfully", "consumes": [ @@ -239,17 +387,163 @@ "application/json" ], "tags": [ - "auth" + "pet" ], "summary": "find all pets", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/dto.ResponseSuccess" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/dto.ResponseInternalErr" + } + }, + "503": { + "description": "Service is down", + "schema": { + "$ref": "#/definitions/dto.ResponseServiceDownErr" + } + } + } + }, + "put": { + "description": "Return the status true of pet if successfully else false", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "pet" + ], + "summary": "change view pet", + "parameters": [ + { + "description": "change view pet dto", + "name": "changeView", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/dto.ChangeViewPetRequest" + } + }, + { + "type": "string", + "description": "pet id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/dto.ResponseSuccess" + } + }, + "400": { + "description": "Invalid request body", + "schema": { + "$ref": "#/definitions/dto.ResponseBadRequestErr" + } + }, + "404": { + "description": "Pet not found", + "schema": { + "$ref": "#/definitions/dto.ResponseNotfoundErr" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/dto.ResponseInternalErr" + } + }, + "503": { + "description": "Service is down", + "schema": { + "$ref": "#/definitions/dto.ResponseServiceDownErr" + } + } + } + }, + "delete": { + "description": "Return the status true of pet if successfully else false", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "pet" + ], + "summary": "delete pet", + "parameters": [ + { + "type": "string", + "description": "pet id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/dto.ResponseSuccess" + } + }, + "400": { + "description": "Invalid request body", + "schema": { + "$ref": "#/definitions/dto.ResponseBadRequestErr" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/dto.ResponseInternalErr" + } + }, + "503": { + "description": "Service is down", + "schema": { + "$ref": "#/definitions/dto.ResponseServiceDownErr" + } + } + } + } + }, + "/v1/pets/create": { + "post": { + "description": "Return the data of pet if successfully", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "pet" + ], + "summary": "create pet", "parameters": [ { "description": "pet dto", - "name": "signup", + "name": "create", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/dto.PetDto" + "$ref": "#/definitions/dto.CreatePetRequest" } } ], @@ -257,7 +551,7 @@ "201": { "description": "Created", "schema": { - "$ref": "#/definitions/dto.PetDto" + "$ref": "#/definitions/dto.ResponseSuccess" } }, "400": { @@ -266,10 +560,191 @@ "$ref": "#/definitions/dto.ResponseBadRequestErr" } }, - "409": { - "description": "Duplicate email", + "500": { + "description": "Internal service error", "schema": { - "$ref": "#/definitions/dto.ResponseConflictErr" + "$ref": "#/definitions/dto.ResponseInternalErr" + } + }, + "503": { + "description": "Service is down", + "schema": { + "$ref": "#/definitions/dto.ResponseServiceDownErr" + } + } + } + } + }, + "/v1/pets/{id}": { + "get": { + "description": "Return the data of pets if successfully", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "auth" + ], + "summary": "find one pet", + "parameters": [ + { + "type": "string", + "description": "pet id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/dto.ResponseSuccess" + } + }, + "404": { + "description": "Pet not found", + "schema": { + "$ref": "#/definitions/dto.ResponseNotfoundErr" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/dto.ResponseInternalErr" + } + }, + "503": { + "description": "Service is down", + "schema": { + "$ref": "#/definitions/dto.ResponseServiceDownErr" + } + } + } + }, + "put": { + "description": "Return the data of pet if successfully", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "pet" + ], + "summary": "update pet", + "parameters": [ + { + "description": "update pet dto", + "name": "update", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/dto.UpdatePetRequest" + } + }, + { + "type": "string", + "description": "pet id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/dto.ResponseSuccess" + } + }, + "400": { + "description": "Invalid request body", + "schema": { + "$ref": "#/definitions/dto.ResponseBadRequestErr" + } + }, + "404": { + "description": "Pet not found", + "schema": { + "$ref": "#/definitions/dto.ResponseNotfoundErr" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/dto.ResponseInternalErr" + } + }, + "503": { + "description": "Service is down", + "schema": { + "$ref": "#/definitions/dto.ResponseServiceDownErr" + } + } + } + } + }, + "/v1/pets/{id}/adopt": { + "put": { + "description": "Return true if the pet is successfully adopted", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "pet" + ], + "summary": "Adopt a pet", + "parameters": [ + { + "type": "string", + "description": "Pet ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "User ID", + "name": "user_id", + "in": "body", + "required": true, + "schema": { + "type": "string" + } + }, + { + "description": "Pet ID", + "name": "pet_id", + "in": "body", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/dto.ResponseSuccess" + } + }, + "400": { + "description": "Invalid request body", + "schema": { + "$ref": "#/definitions/dto.ResponseBadRequestErr" + } + }, + "404": { + "description": "Pet not found", + "schema": { + "$ref": "#/definitions/dto.ResponseNotfoundErr" } }, "500": { @@ -301,6 +776,35 @@ "value": {} } }, + "dto.ChangeViewPetRequest": { + "type": "object", + "required": [ + "visible" + ], + "properties": { + "visible": { + "type": "boolean" + } + } + }, + "dto.CreateLikeRequest": { + "type": "object", + "required": [ + "pet_id", + "user_id" + ], + "properties": { + "pet_id": { + "type": "string" + }, + "user_id": { + "type": "string" + } + } + }, + "dto.CreatePetRequest": { + "type": "object" + }, "dto.Credential": { "type": "object", "properties": { @@ -329,9 +833,6 @@ } } }, - "dto.PetDto": { - "type": "object" - }, "dto.ResponseBadRequestErr": { "type": "object", "properties": { @@ -393,6 +894,20 @@ } } }, + "dto.ResponseNotfoundErr": { + "type": "object", + "properties": { + "data": {}, + "message": { + "type": "string", + "example": "Not found" + }, + "status_code": { + "type": "integer", + "example": 404 + } + } + }, "dto.ResponseServiceDownErr": { "type": "object", "properties": { @@ -407,6 +922,20 @@ } } }, + "dto.ResponseSuccess": { + "type": "object", + "properties": { + "data": {}, + "message": { + "type": "string", + "example": "success" + }, + "status_code": { + "type": "integer", + "example": 200 + } + } + }, "dto.ResponseUnauthorizedErr": { "type": "object", "properties": { @@ -487,6 +1016,65 @@ "type": "string" } } + }, + "dto.UpdatePetRequest": { + "type": "object", + "properties": { + "address": { + "type": "string" + }, + "adopt_by": { + "type": "string" + }, + "background": { + "type": "string" + }, + "birthdate": { + "type": "string" + }, + "caption": { + "type": "string" + }, + "contact": { + "type": "string" + }, + "gender": { + "type": "integer" + }, + "habit": { + "type": "string" + }, + "images": { + "type": "array", + "items": { + "type": "string" + } + }, + "is_club_pet": { + "type": "boolean" + }, + "is_sterile": { + "type": "boolean" + }, + "is_vaccinated": { + "type": "boolean" + }, + "is_visible": { + "type": "boolean" + }, + "name": { + "type": "string" + }, + "species": { + "type": "string" + }, + "status": { + "type": "integer" + }, + "type": { + "type": "string" + } + } } }, "securityDefinitions": { diff --git a/src/docs/swagger.yaml b/src/docs/swagger.yaml index b6ed6da..9fad566 100644 --- a/src/docs/swagger.yaml +++ b/src/docs/swagger.yaml @@ -7,6 +7,25 @@ definitions: type: string value: {} type: object + dto.ChangeViewPetRequest: + properties: + visible: + type: boolean + required: + - visible + type: object + dto.CreateLikeRequest: + properties: + pet_id: + type: string + user_id: + type: string + required: + - pet_id + - user_id + type: object + dto.CreatePetRequest: + type: object dto.Credential: properties: access_token: @@ -26,8 +45,6 @@ definitions: required: - refresh_token type: object - dto.PetDto: - type: object dto.ResponseBadRequestErr: properties: data: @@ -71,6 +88,16 @@ definitions: example: 500 type: integer type: object + dto.ResponseNotfoundErr: + properties: + data: {} + message: + example: Not found + type: string + status_code: + example: 404 + type: integer + type: object dto.ResponseServiceDownErr: properties: data: {} @@ -81,6 +108,16 @@ definitions: example: 503 type: integer type: object + dto.ResponseSuccess: + properties: + data: {} + message: + example: success + type: string + status_code: + example: 200 + type: integer + type: object dto.ResponseUnauthorizedErr: properties: data: {} @@ -137,6 +174,45 @@ definitions: lastname: type: string type: object + dto.UpdatePetRequest: + properties: + address: + type: string + adopt_by: + type: string + background: + type: string + birthdate: + type: string + caption: + type: string + contact: + type: string + gender: + type: integer + habit: + type: string + images: + items: + type: string + type: array + is_club_pet: + type: boolean + is_sterile: + type: boolean + is_vaccinated: + type: boolean + is_visible: + type: boolean + name: + type: string + species: + type: string + status: + type: integer + type: + type: string + type: object info: contact: email: sd.team.sgcu@gmail.com @@ -287,33 +363,148 @@ paths: summary: Signup user tags: - auth - /v1/pet/: + /v1/likes/: + delete: + consumes: + - application/json + description: Return dto.ResponseSuccess if like is successfully deleted + parameters: + - description: user id + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/dto.ResponseSuccess' + "404": + description: like not found + schema: + $ref: '#/definitions/dto.ResponseNotfoundErr' + "500": + description: Internal service error + schema: + $ref: '#/definitions/dto.ResponseInternalErr' + "503": + description: Service is down + schema: + $ref: '#/definitions/dto.ResponseServiceDownErr' + summary: delete like + tags: + - like get: consumes: - application/json - description: Return the data of pets if successfully + description: Return dto.ResponseSuccess parameters: - - description: pet dto + - description: user id + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/dto.ResponseSuccess' + "404": + description: user not found + schema: + $ref: '#/definitions/dto.ResponseNotfoundErr' + "500": + description: Internal service error + schema: + $ref: '#/definitions/dto.ResponseInternalErr' + "503": + description: Service is down + schema: + $ref: '#/definitions/dto.ResponseServiceDownErr' + summary: find likes by user id + tags: + - like + post: + consumes: + - application/json + description: Return dto.ResponseSuccess + parameters: + - description: create like request in: body - name: signup + name: create required: true schema: - $ref: '#/definitions/dto.PetDto' + $ref: '#/definitions/dto.CreateLikeRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/dto.ResponseSuccess' + "400": + description: Invalid request body + schema: + $ref: '#/definitions/dto.ResponseBadRequestErr' + "500": + description: Internal service error + schema: + $ref: '#/definitions/dto.ResponseInternalErr' + "503": + description: Service is down + schema: + $ref: '#/definitions/dto.ResponseServiceDownErr' + summary: create like + tags: + - like + /v1/pets/: + delete: + consumes: + - application/json + description: Return the status true of pet if successfully else false + parameters: + - description: pet id + in: path + name: id + required: true + type: string produces: - application/json responses: "201": description: Created schema: - $ref: '#/definitions/dto.PetDto' + $ref: '#/definitions/dto.ResponseSuccess' "400": description: Invalid request body schema: $ref: '#/definitions/dto.ResponseBadRequestErr' - "409": - description: Duplicate email + "500": + description: Internal service error schema: - $ref: '#/definitions/dto.ResponseConflictErr' + $ref: '#/definitions/dto.ResponseInternalErr' + "503": + description: Service is down + schema: + $ref: '#/definitions/dto.ResponseServiceDownErr' + summary: delete pet + tags: + - pet + get: + consumes: + - application/json + description: Return the data of pets if successfully + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/dto.ResponseSuccess' "500": description: Internal service error schema: @@ -324,7 +515,207 @@ paths: $ref: '#/definitions/dto.ResponseServiceDownErr' summary: find all pets tags: + - pet + put: + consumes: + - application/json + description: Return the status true of pet if successfully else false + parameters: + - description: change view pet dto + in: body + name: changeView + required: true + schema: + $ref: '#/definitions/dto.ChangeViewPetRequest' + - description: pet id + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "201": + description: Created + schema: + $ref: '#/definitions/dto.ResponseSuccess' + "400": + description: Invalid request body + schema: + $ref: '#/definitions/dto.ResponseBadRequestErr' + "404": + description: Pet not found + schema: + $ref: '#/definitions/dto.ResponseNotfoundErr' + "500": + description: Internal service error + schema: + $ref: '#/definitions/dto.ResponseInternalErr' + "503": + description: Service is down + schema: + $ref: '#/definitions/dto.ResponseServiceDownErr' + summary: change view pet + tags: + - pet + /v1/pets/{id}: + get: + consumes: + - application/json + description: Return the data of pets if successfully + parameters: + - description: pet id + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/dto.ResponseSuccess' + "404": + description: Pet not found + schema: + $ref: '#/definitions/dto.ResponseNotfoundErr' + "500": + description: Internal service error + schema: + $ref: '#/definitions/dto.ResponseInternalErr' + "503": + description: Service is down + schema: + $ref: '#/definitions/dto.ResponseServiceDownErr' + summary: find one pet + tags: - auth + put: + consumes: + - application/json + description: Return the data of pet if successfully + parameters: + - description: update pet dto + in: body + name: update + required: true + schema: + $ref: '#/definitions/dto.UpdatePetRequest' + - description: pet id + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "201": + description: Created + schema: + $ref: '#/definitions/dto.ResponseSuccess' + "400": + description: Invalid request body + schema: + $ref: '#/definitions/dto.ResponseBadRequestErr' + "404": + description: Pet not found + schema: + $ref: '#/definitions/dto.ResponseNotfoundErr' + "500": + description: Internal service error + schema: + $ref: '#/definitions/dto.ResponseInternalErr' + "503": + description: Service is down + schema: + $ref: '#/definitions/dto.ResponseServiceDownErr' + summary: update pet + tags: + - pet + /v1/pets/{id}/adopt: + put: + consumes: + - application/json + description: Return true if the pet is successfully adopted + parameters: + - description: Pet ID + in: path + name: id + required: true + type: string + - description: User ID + in: body + name: user_id + required: true + schema: + type: string + - description: Pet ID + in: body + name: pet_id + required: true + schema: + type: string + produces: + - application/json + responses: + "201": + description: Created + schema: + $ref: '#/definitions/dto.ResponseSuccess' + "400": + description: Invalid request body + schema: + $ref: '#/definitions/dto.ResponseBadRequestErr' + "404": + description: Pet not found + schema: + $ref: '#/definitions/dto.ResponseNotfoundErr' + "500": + description: Internal service error + schema: + $ref: '#/definitions/dto.ResponseInternalErr' + "503": + description: Service is down + schema: + $ref: '#/definitions/dto.ResponseServiceDownErr' + summary: Adopt a pet + tags: + - pet + /v1/pets/create: + post: + consumes: + - application/json + description: Return the data of pet if successfully + parameters: + - description: pet dto + in: body + name: create + required: true + schema: + $ref: '#/definitions/dto.CreatePetRequest' + produces: + - application/json + responses: + "201": + description: Created + schema: + $ref: '#/definitions/dto.ResponseSuccess' + "400": + description: Invalid request body + schema: + $ref: '#/definitions/dto.ResponseBadRequestErr' + "500": + description: Internal service error + schema: + $ref: '#/definitions/dto.ResponseInternalErr' + "503": + description: Service is down + schema: + $ref: '#/definitions/dto.ResponseServiceDownErr' + summary: create pet + tags: + - pet schemes: - https - http From 8afc8d9551efcf0ac1de442f4dd426aafc268444 Mon Sep 17 00:00:00 2001 From: Gear <84141000+macgeargear@users.noreply.github.com> Date: Mon, 8 Jan 2024 10:31:13 +0700 Subject: [PATCH 2/7] feat: add `IsLike` property to `PetResponse` --- src/app/dto/pet.dto.go | 1 + src/app/handler/pet/pet.handler.go | 39 +++++++++++++++++------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/app/dto/pet.dto.go b/src/app/dto/pet.dto.go index 0d7c5b1..6608ccd 100644 --- a/src/app/dto/pet.dto.go +++ b/src/app/dto/pet.dto.go @@ -28,6 +28,7 @@ type PetResponse struct { Contact string `json:"contact"` AdoptBy string `json:"adopt_by"` Images []ImageResponse `json:"images"` + IsLike *bool `json:"is_like"` } type CreatePetRequest struct { diff --git a/src/app/handler/pet/pet.handler.go b/src/app/handler/pet/pet.handler.go index 7dae48c..2ddd90b 100644 --- a/src/app/handler/pet/pet.handler.go +++ b/src/app/handler/pet/pet.handler.go @@ -26,14 +26,15 @@ func NewHandler(service petSvc.Service, imageService imageSvc.Service, validate // FindAll is a function that return all pets in database // @Summary find all pets // @Description Return the data of pets if successfully -// @Tags auth +// @Tags pet // @Accept json // @Produce json -// @Success 200 {object} dto.PetDto +// @Success 200 {object} dto.ResponseSuccess // @Failure 500 {object} dto.ResponseInternalErr "Internal service error" // @Failure 503 {object} dto.ResponseServiceDownErr "Service is down" // @Router /v1/pets/ [get] func (h *Handler) FindAll(c router.IContext) { + token := response, respErr := h.service.FindAll() if respErr != nil { c.JSON(respErr.StatusCode, respErr) @@ -55,12 +56,13 @@ func (h *Handler) FindAll(c router.IContext) { // @Tags auth // @Accept json // @Produce json -// @Success 200 {object} dto.PetDto -// @Failure 400 {object} dto.ResponseBadRequestErr "Invalid request body" +// @Success 200 {object} dto.ResponseSuccess +// @Failure 404 {object} dto.ResponseNotfoundErr "Pet not found" // @Failure 500 {object} dto.ResponseInternalErr "Internal service error" // @Failure 503 {object} dto.ResponseServiceDownErr "Service is down" // @Router /v1/pets/{id} [get] func (h *Handler) FindOne(c router.IContext) { + token := c.Token() id, err := c.Param("id") if err != nil { c.JSON(http.StatusInternalServerError, dto.ResponseErr{ @@ -89,10 +91,10 @@ func (h *Handler) FindOne(c router.IContext) { // @Summary create pet // @Description Return the data of pet if successfully // @Param create body dto.CreatePetRequest true "pet dto" -// @Tags auth +// @Tags pet // @Accept json // @Produce json -// @Success 201 {object} dto.PetDto +// @Success 201 {object} dto.ResponseSuccess // @Failure 400 {object} dto.ResponseBadRequestErr "Invalid request body" // @Failure 500 {object} dto.ResponseInternalErr "Internal service error" // @Failure 503 {object} dto.ResponseServiceDownErr "Service is down" @@ -140,12 +142,13 @@ func (h *Handler) Create(c router.IContext) { // @Summary update pet // @Description Return the data of pet if successfully // @Param update body dto.UpdatePetRequest true "update pet dto" -// @Param id path stirng true "pet id" -// @Tags auth +// @Param id path string true "pet id" +// @Tags pet // @Accept json // @Produce json -// @Success 201 {object} dto.PetDto +// @Success 201 {object} dto.ResponseSuccess // @Failure 400 {object} dto.ResponseBadRequestErr "Invalid request body" +// @Failure 404 {object} dto.ResponseNotfoundErr "Pet not found" // @Failure 500 {object} dto.ResponseInternalErr "Internal service error" // @Failure 503 {object} dto.ResponseServiceDownErr "Service is down" // @Router /v1/pets/{id} [put] @@ -202,13 +205,14 @@ func (h *Handler) Update(c router.IContext) { // Change is a function that change visibility of pet in database // @Summary change view pet // @Description Return the status true of pet if successfully else false -// @Param change view body dto.ChangeViewPetRequest true "change view pet dto" -// @Param id string true "pet id" -// @Tags auth +// @Param changeView body dto.ChangeViewPetRequest true "change view pet dto" +// @Param id path string true "pet id" +// @Tags pet // @Accept json // @Produce json -// @Success 201 {object} bool +// @Success 201 {object} dto.ResponseSuccess // @Failure 400 {object} dto.ResponseBadRequestErr "Invalid request body" +// @Failure 404 {object} dto.ResponseNotfoundErr "Pet not found" // @Failure 500 {object} dto.ResponseInternalErr "Internal service error" // @Failure 503 {object} dto.ResponseServiceDownErr "Service is down" // @Router /v1/pets/ [put] @@ -265,11 +269,11 @@ func (h *Handler) ChangeView(c router.IContext) { // Delete is a function that delete pet in database // @Summary delete pet // @Description Return the status true of pet if successfully else false -// @Param id string true "pet id" -// @Tags auth +// @Param id path string true "pet id" +// @Tags pet // @Accept json // @Produce json -// @Success 201 {object} bool +// @Success 201 {object} dto.ResponseSuccess // @Failure 400 {object} dto.ResponseBadRequestErr "Invalid request body" // @Failure 500 {object} dto.ResponseInternalErr "Internal service error" // @Failure 503 {object} dto.ResponseServiceDownErr "Service is down" @@ -308,8 +312,9 @@ func (h *Handler) Delete(c router.IContext) { // @Tags pet // @Accept json // @Produce json -// @Success 201 {object} bool +// @Success 201 {object} dto.ResponseSuccess // @Failure 400 {object} dto.ResponseBadRequestErr "Invalid request body" +// @Failure 404 {object} dto.ResponseNotfoundErr "Pet not found" // @Failure 500 {object} dto.ResponseInternalErr "Internal service error" // @Failure 503 {object} dto.ResponseServiceDownErr "Service is down" // @Router /v1/pets/{id}/adopt [put] From 312807844f8da52f2f31d7ac6975cbe07717f28b Mon Sep 17 00:00:00 2001 From: Gear <84141000+macgeargear@users.noreply.github.com> Date: Mon, 8 Jan 2024 10:31:20 +0700 Subject: [PATCH 3/7] docs --- src/app/handler/like/like.handler.go | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/app/handler/like/like.handler.go b/src/app/handler/like/like.handler.go index ab57fd8..95e0b7e 100644 --- a/src/app/handler/like/like.handler.go +++ b/src/app/handler/like/like.handler.go @@ -21,6 +21,18 @@ func NewHandler(service likeSvc.Service, validate validator.IDtoValidator) *Hand return &Handler{service, validate} } +// FindByUserId is a function that return all petID and userID that user liked. +// @Summary find likes by user id +// @Description Return dto.ResponseSuccess +// @Param id path string true "user id" +// @Tags like +// @Accept json +// @Produce json +// @Success 200 {object} dto.ResponseSuccess +// @Failure 404 {object} dto.ResponseNotfoundErr "user not found" +// @Failure 500 {object} dto.ResponseInternalErr "Internal service error" +// @Failure 503 {object} dto.ResponseServiceDownErr "Service is down" +// @Router /v1/likes/ [get] func (h *Handler) FindByUserId(c router.IContext) { id, err := c.Param("id") if err != nil { @@ -46,6 +58,18 @@ func (h *Handler) FindByUserId(c router.IContext) { return } +// Create is a function for creating a `like` for a pet that a user is interested +// @Summary create like +// @Description Return dto.ResponseSuccess +// @Param create body dto.CreateLikeRequest true "create like request" +// @Tags like +// @Accept json +// @Produce json +// @Success 200 {object} dto.ResponseSuccess +// @Failure 400 {object} dto.ResponseBadRequestErr "Invalid request body" +// @Failure 500 {object} dto.ResponseInternalErr "Internal service error" +// @Failure 503 {object} dto.ResponseServiceDownErr "Service is down" +// @Router /v1/likes/ [post] func (h *Handler) Create(c router.IContext) { request := &dto.CreateLikeRequest{} err := c.Bind(request) @@ -85,6 +109,18 @@ func (h *Handler) Create(c router.IContext) { return } +// Create is a function for delete like in database +// @Summary delete like +// @Description Return dto.ResponseSuccess if like is successfully deleted +// @Param id path string true "user id" +// @Tags like +// @Accept json +// @Produce json +// @Success 200 {object} dto.ResponseSuccess +// @Failure 404 {object} dto.ResponseNotfoundErr "like not found" +// @Failure 500 {object} dto.ResponseInternalErr "Internal service error" +// @Failure 503 {object} dto.ResponseServiceDownErr "Service is down" +// @Router /v1/likes/ [delete] func (h *Handler) Delete(c router.IContext) { id, err := c.Param("id") if err != nil { From 0806d17ee65f414f0d63f06078337f21cbe3f2cc Mon Sep 17 00:00:00 2001 From: Gear <84141000+macgeargear@users.noreply.github.com> Date: Mon, 8 Jan 2024 10:32:01 +0700 Subject: [PATCH 4/7] feat: util for adding `isLike` for `Pet` --- src/app/utils/pet/pet.utils.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/app/utils/pet/pet.utils.go b/src/app/utils/pet/pet.utils.go index 1f68987..9505f1c 100644 --- a/src/app/utils/pet/pet.utils.go +++ b/src/app/utils/pet/pet.utils.go @@ -160,3 +160,23 @@ func extractImages(images []*imgproto.Image) []dto.ImageResponse { } return result } + +func IsLike(petId string, likes []*dto.LikeResponse) *bool { + for _, like := range likes { + if like.PetID == petId { + return boolAddr(true) + } + } + return boolAddr(false) +} + +func MapIsLikeToPets(likes []*dto.LikeResponse, pets []*dto.PetResponse) []*dto.PetResponse { + for _, pet := range pets { + pet.IsLike = IsLike(pet.Id, likes) + } + return pets +} + +func boolAddr(b bool) *bool { + return &b +} From 59b8901e8e0a7a97a718485c7dcbcf86322ef8c7 Mon Sep 17 00:00:00 2001 From: Gear <84141000+macgeargear@users.noreply.github.com> Date: Mon, 8 Jan 2024 18:15:36 +0700 Subject: [PATCH 5/7] feat: add `isLike` in `petResponse` if there're token --- src/app/handler/pet/pet.handler.go | 33 +++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/app/handler/pet/pet.handler.go b/src/app/handler/pet/pet.handler.go index 2ddd90b..136aa1f 100644 --- a/src/app/handler/pet/pet.handler.go +++ b/src/app/handler/pet/pet.handler.go @@ -7,20 +7,27 @@ import ( "github.com/isd-sgcu/johnjud-gateway/src/app/constant" "github.com/isd-sgcu/johnjud-gateway/src/app/dto" "github.com/isd-sgcu/johnjud-gateway/src/app/router" + petUtils "github.com/isd-sgcu/johnjud-gateway/src/app/utils/pet" "github.com/isd-sgcu/johnjud-gateway/src/app/validator" petconst "github.com/isd-sgcu/johnjud-gateway/src/constant/pet" imageSvc "github.com/isd-sgcu/johnjud-gateway/src/pkg/service/image" + likeSvc "github.com/isd-sgcu/johnjud-gateway/src/pkg/service/like" petSvc "github.com/isd-sgcu/johnjud-gateway/src/pkg/service/pet" ) type Handler struct { service petSvc.Service + likeService likeSvc.Service imageService imageSvc.Service validate validator.IDtoValidator } -func NewHandler(service petSvc.Service, imageService imageSvc.Service, validate validator.IDtoValidator) *Handler { - return &Handler{service, imageService, validate} +func NewHandler(service petSvc.Service, imageService imageSvc.Service, likeService likeSvc.Service, validate validator.IDtoValidator) *Handler { + return &Handler{ + service: service, + imageService: imageService, + likeService: likeService, + } } // FindAll is a function that return all pets in database @@ -34,17 +41,25 @@ func NewHandler(service petSvc.Service, imageService imageSvc.Service, validate // @Failure 503 {object} dto.ResponseServiceDownErr "Service is down" // @Router /v1/pets/ [get] func (h *Handler) FindAll(c router.IContext) { - token := + userId := c.UserID() response, respErr := h.service.FindAll() if respErr != nil { c.JSON(respErr.StatusCode, respErr) return } + likeResponse, likeRespErr := h.likeService.FindByUserId(userId) + if likeRespErr != nil { + c.JSON(respErr.StatusCode, likeRespErr) + return + } + + petResponse := petUtils.MapIsLikeToPets(likeResponse, response) + c.JSON(http.StatusOK, dto.ResponseSuccess{ StatusCode: http.StatusOK, Message: petconst.FindAllPetSuccessMessage, - Data: response, + Data: petResponse, }) return } @@ -62,7 +77,7 @@ func (h *Handler) FindAll(c router.IContext) { // @Failure 503 {object} dto.ResponseServiceDownErr "Service is down" // @Router /v1/pets/{id} [get] func (h *Handler) FindOne(c router.IContext) { - token := c.Token() + userId := c.UserID() id, err := c.Param("id") if err != nil { c.JSON(http.StatusInternalServerError, dto.ResponseErr{ @@ -79,6 +94,14 @@ func (h *Handler) FindOne(c router.IContext) { return } + likeResponse, likeRespErr := h.likeService.FindByUserId(userId) + if likeRespErr != nil { + c.JSON(respErr.StatusCode, likeRespErr) + return + } + + response.IsLike = petUtils.IsLike(id, likeResponse) + c.JSON(http.StatusOK, dto.ResponseSuccess{ StatusCode: http.StatusOK, Message: petconst.FindOnePetSuccessMessage, From 6ba63d5beb782ed819beed1414bc59124107ae80 Mon Sep 17 00:00:00 2001 From: Gear <84141000+macgeargear@users.noreply.github.com> Date: Mon, 8 Jan 2024 18:15:42 +0700 Subject: [PATCH 6/7] fix: test --- src/app/handler/pet/pet.handler_test.go | 55 +++++++++++++++++-------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/src/app/handler/pet/pet.handler_test.go b/src/app/handler/pet/pet.handler_test.go index 659e221..0004db8 100644 --- a/src/app/handler/pet/pet.handler_test.go +++ b/src/app/handler/pet/pet.handler_test.go @@ -11,6 +11,7 @@ import ( "github.com/isd-sgcu/johnjud-gateway/src/constant/pet" routerMock "github.com/isd-sgcu/johnjud-gateway/src/mocks/router" imageMock "github.com/isd-sgcu/johnjud-gateway/src/mocks/service/image" + likeMock "github.com/isd-sgcu/johnjud-gateway/src/mocks/service/like" petMock "github.com/isd-sgcu/johnjud-gateway/src/mocks/service/pet" validatorMock "github.com/isd-sgcu/johnjud-gateway/src/mocks/validator" @@ -141,13 +142,14 @@ func (t *PetHandlerTest) TestFindAllSuccess() { petSvc := petMock.NewMockService(controller) imageSvc := imageMock.NewMockService(controller) + likeSvc := likeMock.NewMockService(controller) validator := validatorMock.NewMockIDtoValidator(controller) context := routerMock.NewMockIContext(controller) petSvc.EXPECT().FindAll().Return(findAllResponse, nil) context.EXPECT().JSON(http.StatusOK, expectedResponse) - handler := NewHandler(petSvc, imageSvc, validator) + handler := NewHandler(petSvc, imageSvc, likeSvc, validator) handler.FindAll(context) } @@ -163,6 +165,7 @@ func (t *PetHandlerTest) TestFindOneSuccess() { petSvc := petMock.NewMockService(controller) imageSvc := imageMock.NewMockService(controller) + likeSvc := likeMock.NewMockService(controller) validator := validatorMock.NewMockIDtoValidator(controller) context := routerMock.NewMockIContext(controller) @@ -170,7 +173,7 @@ func (t *PetHandlerTest) TestFindOneSuccess() { petSvc.EXPECT().FindOne(t.Pet.Id).Return(findOneResponse, nil) context.EXPECT().JSON(http.StatusOK, expectedResponse) - handler := NewHandler(petSvc, imageSvc, validator) + handler := NewHandler(petSvc, imageSvc, likeSvc, validator) handler.FindOne(context) } @@ -181,6 +184,7 @@ func (t *PetHandlerTest) TestFindOneNotFoundErr() { petSvc := petMock.NewMockService(controller) imageSvc := imageMock.NewMockService(controller) + likeSvc := likeMock.NewMockService(controller) validator := validatorMock.NewMockIDtoValidator(controller) context := routerMock.NewMockIContext(controller) @@ -188,7 +192,7 @@ func (t *PetHandlerTest) TestFindOneNotFoundErr() { petSvc.EXPECT().FindOne(t.Pet.Id).Return(nil, findOneResponse) context.EXPECT().JSON(http.StatusNotFound, findOneResponse) - handler := NewHandler(petSvc, imageSvc, validator) + handler := NewHandler(petSvc, imageSvc, likeSvc, validator) handler.FindOne(context) } @@ -199,6 +203,7 @@ func (t *PetHandlerTest) TestFindOneGrpcErr() { petSvc := petMock.NewMockService(controller) imageSvc := imageMock.NewMockService(controller) + likeSvc := likeMock.NewMockService(controller) validator := validatorMock.NewMockIDtoValidator(controller) context := routerMock.NewMockIContext(controller) @@ -206,7 +211,7 @@ func (t *PetHandlerTest) TestFindOneGrpcErr() { petSvc.EXPECT().FindOne(t.Pet.Id).Return(nil, findOneResponse) context.EXPECT().JSON(http.StatusServiceUnavailable, findOneResponse) - handler := NewHandler(petSvc, imageSvc, validator) + handler := NewHandler(petSvc, imageSvc, likeSvc, validator) handler.FindOne(context) } @@ -222,6 +227,7 @@ func (t *PetHandlerTest) TestCreateSuccess() { petSvc := petMock.NewMockService(controller) imageSvc := imageMock.NewMockService(controller) + likeSvc := likeMock.NewMockService(controller) validator := validatorMock.NewMockIDtoValidator(controller) context := routerMock.NewMockIContext(controller) @@ -230,7 +236,7 @@ func (t *PetHandlerTest) TestCreateSuccess() { petSvc.EXPECT().Create(t.CreatePetRequest).Return(createResponse, nil) context.EXPECT().JSON(http.StatusCreated, expectedResponse) - handler := NewHandler(petSvc, imageSvc, validator) + handler := NewHandler(petSvc, imageSvc, likeSvc, validator) handler.Create(context) } @@ -241,6 +247,7 @@ func (t *PetHandlerTest) TestCreateGrpcErr() { petSvc := petMock.NewMockService(controller) imageSvc := imageMock.NewMockService(controller) + likeSvc := likeMock.NewMockService(controller) validator := validatorMock.NewMockIDtoValidator(controller) context := routerMock.NewMockIContext(controller) @@ -249,7 +256,7 @@ func (t *PetHandlerTest) TestCreateGrpcErr() { petSvc.EXPECT().Create(t.CreatePetRequest).Return(nil, createErrorResponse) context.EXPECT().JSON(http.StatusServiceUnavailable, createErrorResponse) - handler := NewHandler(petSvc, imageSvc, validator) + handler := NewHandler(petSvc, imageSvc, likeSvc, validator) handler.Create(context) } @@ -265,6 +272,7 @@ func (t *PetHandlerTest) TestUpdateSuccess() { petSvc := petMock.NewMockService(controller) imageSvc := imageMock.NewMockService(controller) + likeSvc := likeMock.NewMockService(controller) validator := validatorMock.NewMockIDtoValidator(controller) context := routerMock.NewMockIContext(controller) @@ -274,7 +282,7 @@ func (t *PetHandlerTest) TestUpdateSuccess() { petSvc.EXPECT().Update(t.Pet.Id, t.UpdatePetRequest).Return(updateResponse, nil) context.EXPECT().JSON(http.StatusOK, expectedResponse) - handler := NewHandler(petSvc, imageSvc, validator) + handler := NewHandler(petSvc, imageSvc, likeSvc, validator) handler.Update(context) } @@ -285,6 +293,7 @@ func (t *PetHandlerTest) TestUpdateNotFound() { petSvc := petMock.NewMockService(controller) imageSvc := imageMock.NewMockService(controller) + likeSvc := likeMock.NewMockService(controller) validator := validatorMock.NewMockIDtoValidator(controller) context := routerMock.NewMockIContext(controller) @@ -294,7 +303,7 @@ func (t *PetHandlerTest) TestUpdateNotFound() { petSvc.EXPECT().Update(t.Pet.Id, t.UpdatePetRequest).Return(nil, updateResponse) context.EXPECT().JSON(http.StatusNotFound, updateResponse) - handler := NewHandler(petSvc, imageSvc, validator) + handler := NewHandler(petSvc, imageSvc, likeSvc, validator) handler.Update(context) } @@ -305,6 +314,7 @@ func (t *PetHandlerTest) TestUpdateGrpcErr() { petSvc := petMock.NewMockService(controller) imageSvc := imageMock.NewMockService(controller) + likeSvc := likeMock.NewMockService(controller) validator := validatorMock.NewMockIDtoValidator(controller) context := routerMock.NewMockIContext(controller) @@ -314,7 +324,7 @@ func (t *PetHandlerTest) TestUpdateGrpcErr() { petSvc.EXPECT().Update(t.Pet.Id, t.UpdatePetRequest).Return(nil, updateResponse) context.EXPECT().JSON(http.StatusServiceUnavailable, updateResponse) - handler := NewHandler(petSvc, imageSvc, validator) + handler := NewHandler(petSvc, imageSvc, likeSvc, validator) handler.Update(context) } @@ -332,6 +342,7 @@ func (t *PetHandlerTest) TestDeleteSuccess() { petSvc := petMock.NewMockService(controller) imageSvc := imageMock.NewMockService(controller) + likeSvc := likeMock.NewMockService(controller) validator := validatorMock.NewMockIDtoValidator(controller) context := routerMock.NewMockIContext(controller) @@ -339,7 +350,7 @@ func (t *PetHandlerTest) TestDeleteSuccess() { petSvc.EXPECT().Delete(t.Pet.Id).Return(deleteResponse, nil) context.EXPECT().JSON(http.StatusOK, expectedResponse) - handler := NewHandler(petSvc, imageSvc, validator) + handler := NewHandler(petSvc, imageSvc, likeSvc, validator) handler.Delete(context) } func (t *PetHandlerTest) TestDeleteNotFound() { @@ -351,6 +362,7 @@ func (t *PetHandlerTest) TestDeleteNotFound() { petSvc := petMock.NewMockService(controller) imageSvc := imageMock.NewMockService(controller) + likeSvc := likeMock.NewMockService(controller) validator := validatorMock.NewMockIDtoValidator(controller) context := routerMock.NewMockIContext(controller) @@ -358,7 +370,7 @@ func (t *PetHandlerTest) TestDeleteNotFound() { petSvc.EXPECT().Delete(t.Pet.Id).Return(deleteResponse, t.NotFoundErr) context.EXPECT().JSON(http.StatusNotFound, t.NotFoundErr) - handler := NewHandler(petSvc, imageSvc, validator) + handler := NewHandler(petSvc, imageSvc, likeSvc, validator) handler.Delete(context) } @@ -371,6 +383,7 @@ func (t *PetHandlerTest) TestDeleteGrpcErr() { petSvc := petMock.NewMockService(controller) imageSvc := imageMock.NewMockService(controller) + likeSvc := likeMock.NewMockService(controller) validator := validatorMock.NewMockIDtoValidator(controller) context := routerMock.NewMockIContext(controller) @@ -378,7 +391,7 @@ func (t *PetHandlerTest) TestDeleteGrpcErr() { petSvc.EXPECT().Delete(t.Pet.Id).Return(deleteResponse, t.ServiceDownErr) context.EXPECT().JSON(http.StatusServiceUnavailable, t.ServiceDownErr) - handler := NewHandler(petSvc, imageSvc, validator) + handler := NewHandler(petSvc, imageSvc, likeSvc, validator) handler.Delete(context) } @@ -396,6 +409,7 @@ func (t *PetHandlerTest) TestChangeViewSuccess() { petSvc := petMock.NewMockService(controller) imageSvc := imageMock.NewMockService(controller) + likeSvc := likeMock.NewMockService(controller) validator := validatorMock.NewMockIDtoValidator(controller) context := routerMock.NewMockIContext(controller) @@ -405,7 +419,7 @@ func (t *PetHandlerTest) TestChangeViewSuccess() { petSvc.EXPECT().ChangeView(t.Pet.Id, t.ChangeViewPetRequest).Return(changeViewResponse, nil) context.EXPECT().JSON(http.StatusOK, expectedResponse) - handler := NewHandler(petSvc, imageSvc, validator) + handler := NewHandler(petSvc, imageSvc, likeSvc, validator) handler.ChangeView(context) } @@ -418,6 +432,7 @@ func (t *PetHandlerTest) TestChangeViewNotFound() { petSvc := petMock.NewMockService(controller) imageSvc := imageMock.NewMockService(controller) + likeSvc := likeMock.NewMockService(controller) validator := validatorMock.NewMockIDtoValidator(controller) context := routerMock.NewMockIContext(controller) @@ -427,7 +442,7 @@ func (t *PetHandlerTest) TestChangeViewNotFound() { petSvc.EXPECT().ChangeView(t.Pet.Id, t.ChangeViewPetRequest).Return(changeViewResponse, t.NotFoundErr) context.EXPECT().JSON(http.StatusNotFound, t.NotFoundErr) - handler := NewHandler(petSvc, imageSvc, validator) + handler := NewHandler(petSvc, imageSvc, likeSvc, validator) handler.ChangeView(context) } @@ -440,6 +455,7 @@ func (t *PetHandlerTest) TestChangeViewGrpcErr() { petSvc := petMock.NewMockService(controller) imageSvc := imageMock.NewMockService(controller) + likeSvc := likeMock.NewMockService(controller) validator := validatorMock.NewMockIDtoValidator(controller) context := routerMock.NewMockIContext(controller) @@ -449,7 +465,7 @@ func (t *PetHandlerTest) TestChangeViewGrpcErr() { petSvc.EXPECT().ChangeView(t.Pet.Id, t.ChangeViewPetRequest).Return(changeViewResponse, t.ServiceDownErr) context.EXPECT().JSON(http.StatusServiceUnavailable, t.ServiceDownErr) - handler := NewHandler(petSvc, imageSvc, validator) + handler := NewHandler(petSvc, imageSvc, likeSvc, validator) handler.ChangeView(context) } @@ -467,6 +483,7 @@ func (t *PetHandlerTest) TestAdoptSuccess() { petSvc := petMock.NewMockService(controller) imageSvc := imageMock.NewMockService(controller) + likeSvc := likeMock.NewMockService(controller) validator := validatorMock.NewMockIDtoValidator(controller) context := routerMock.NewMockIContext(controller) @@ -476,7 +493,7 @@ func (t *PetHandlerTest) TestAdoptSuccess() { petSvc.EXPECT().Adopt(t.Pet.Id, t.AdoptByRequest).Return(adoptByResponse, nil) context.EXPECT().JSON(http.StatusOK, expectedResponse) - handler := NewHandler(petSvc, imageSvc, validator) + handler := NewHandler(petSvc, imageSvc, likeSvc, validator) handler.Adopt(context) } @@ -489,6 +506,7 @@ func (t *PetHandlerTest) TestAdoptNotFound() { petSvc := petMock.NewMockService(controller) imageSvc := imageMock.NewMockService(controller) + likeSvc := likeMock.NewMockService(controller) validator := validatorMock.NewMockIDtoValidator(controller) context := routerMock.NewMockIContext(controller) @@ -498,7 +516,7 @@ func (t *PetHandlerTest) TestAdoptNotFound() { petSvc.EXPECT().Adopt(t.Pet.Id, t.AdoptByRequest).Return(adoptByResponse, t.NotFoundErr) context.EXPECT().JSON(http.StatusNotFound, t.NotFoundErr) - handler := NewHandler(petSvc, imageSvc, validator) + handler := NewHandler(petSvc, imageSvc, likeSvc, validator) handler.Adopt(context) } @@ -511,6 +529,7 @@ func (t *PetHandlerTest) TestAdoptGrpcErr() { petSvc := petMock.NewMockService(controller) imageSvc := imageMock.NewMockService(controller) + likeSvc := likeMock.NewMockService(controller) validator := validatorMock.NewMockIDtoValidator(controller) context := routerMock.NewMockIContext(controller) @@ -520,6 +539,6 @@ func (t *PetHandlerTest) TestAdoptGrpcErr() { petSvc.EXPECT().Adopt(t.Pet.Id, t.AdoptByRequest).Return(adoptByResponse, t.ServiceDownErr) context.EXPECT().JSON(http.StatusServiceUnavailable, t.ServiceDownErr) - handler := NewHandler(petSvc, imageSvc, validator) + handler := NewHandler(petSvc, imageSvc, likeSvc, validator) handler.Adopt(context) } From 0ddc8ee2bd289e578d7298037f5fdb521e62beb5 Mon Sep 17 00:00:00 2001 From: Gear <84141000+macgeargear@users.noreply.github.com> Date: Mon, 8 Jan 2024 18:16:01 +0700 Subject: [PATCH 7/7] chore --- src/main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.go b/src/main.go index 2d354c7..70db437 100644 --- a/src/main.go +++ b/src/main.go @@ -108,14 +108,14 @@ func main() { imageClient := imageProto.NewImageServiceClient(fileConn) imageService := imageSvc.NewService(imageClient) - petClient := petProto.NewPetServiceClient(backendConn) - petService := petSvc.NewService(petClient) - petHandler := petHdr.NewHandler(petService, imageService, v) - likeClient := likeProto.NewLikeServiceClient(backendConn) likeService := likeSvc.NewService(likeClient) likeHandler := likeHdr.NewHandler(likeService, v) + petClient := petProto.NewPetServiceClient(backendConn) + petService := petSvc.NewService(petClient) + petHandler := petHdr.NewHandler(petService, imageService, likeService, v) + r := router.NewFiberRouter(&authGuard, conf.App) r.GetUser("/:id", userHandler.FindOne)