From 797e5a473056c26a50fbcec33a1a49a6671a73ef Mon Sep 17 00:00:00 2001 From: Idhibhat Pankam Date: Tue, 9 Jan 2024 22:51:22 +0700 Subject: [PATCH] fix: like handler use lighter success resp --- src/app/dto/common.dto.go | 6 ------ src/app/handler/like/like.handler.go | 19 +++---------------- src/app/handler/like/like.handler_test.go | 19 +++---------------- 3 files changed, 6 insertions(+), 38 deletions(-) diff --git a/src/app/dto/common.dto.go b/src/app/dto/common.dto.go index ba64d2d..611c90e 100644 --- a/src/app/dto/common.dto.go +++ b/src/app/dto/common.dto.go @@ -67,9 +67,3 @@ type ResponseGatewayTimeoutErr struct { Message string `json:"message" example:"Connection timeout"` Data interface{} `json:"data"` } - -type ResponseSuccess struct { - StatusCode int `json:"status_code" example:"200"` - Message string `json:"message" example:"success"` - Data interface{} `json:"data"` -} diff --git a/src/app/handler/like/like.handler.go b/src/app/handler/like/like.handler.go index ab57fd8..accafc0 100644 --- a/src/app/handler/like/like.handler.go +++ b/src/app/handler/like/like.handler.go @@ -8,7 +8,6 @@ import ( "github.com/isd-sgcu/johnjud-gateway/src/app/dto" "github.com/isd-sgcu/johnjud-gateway/src/app/router" "github.com/isd-sgcu/johnjud-gateway/src/app/validator" - likeConst "github.com/isd-sgcu/johnjud-gateway/src/constant/like" likeSvc "github.com/isd-sgcu/johnjud-gateway/src/pkg/service/like" ) @@ -38,11 +37,7 @@ func (h *Handler) FindByUserId(c router.IContext) { return } - c.JSON(http.StatusOK, dto.ResponseSuccess{ - StatusCode: http.StatusOK, - Message: likeConst.FindLikeSuccessMessage, - Data: response, - }) + c.JSON(http.StatusOK, response) return } @@ -77,11 +72,7 @@ func (h *Handler) Create(c router.IContext) { return } - c.JSON(http.StatusCreated, dto.ResponseSuccess{ - StatusCode: http.StatusCreated, - Message: likeConst.CreateLikeSuccessMessage, - Data: response, - }) + c.JSON(http.StatusCreated, response) return } @@ -102,10 +93,6 @@ func (h *Handler) Delete(c router.IContext) { return } - c.JSON(http.StatusOK, dto.ResponseSuccess{ - StatusCode: http.StatusOK, - Message: likeConst.DelteLikeSuccessMessage, - Data: res, - }) + c.JSON(http.StatusOK, res) return } diff --git a/src/app/handler/like/like.handler_test.go b/src/app/handler/like/like.handler_test.go index db72655..ed7debe 100644 --- a/src/app/handler/like/like.handler_test.go +++ b/src/app/handler/like/like.handler_test.go @@ -9,7 +9,6 @@ import ( errConst "github.com/isd-sgcu/johnjud-gateway/src/app/constant" "github.com/isd-sgcu/johnjud-gateway/src/app/dto" utils "github.com/isd-sgcu/johnjud-gateway/src/app/utils/like" - likeConst "github.com/isd-sgcu/johnjud-gateway/src/constant/like" routerMock "github.com/isd-sgcu/johnjud-gateway/src/mocks/router" likeMock "github.com/isd-sgcu/johnjud-gateway/src/mocks/service/like" validatorMock "github.com/isd-sgcu/johnjud-gateway/src/mocks/validator" @@ -74,11 +73,7 @@ func (t *LikeHandlerTest) SetupTest() { func (t *LikeHandlerTest) TestFindLikesSuccess() { findLikeResponse := utils.ProtoToDtoList(t.Likes) - expectedResponse := dto.ResponseSuccess{ - StatusCode: http.StatusOK, - Message: likeConst.FindLikeSuccessMessage, - Data: findLikeResponse, - } + expectedResponse := findLikeResponse controller := gomock.NewController(t.T()) @@ -147,11 +142,7 @@ func (t *LikeHandlerTest) TestFindLikeInternalError() { func (t *LikeHandlerTest) TestCreateSuccess() { createLikeResponse := utils.ProtoToDto(t.Like) - expectedResponse := dto.ResponseSuccess{ - StatusCode: http.StatusCreated, - Message: likeConst.CreateLikeSuccessMessage, - Data: createLikeResponse, - } + expectedResponse := createLikeResponse controller := gomock.NewController(t.T()) @@ -208,11 +199,7 @@ func (t *LikeHandlerTest) TestDeleteSuccess() { deleteResponse := &dto.DeleteLikeResponse{ Success: true, } - expectedResponse := dto.ResponseSuccess{ - StatusCode: http.StatusOK, - Message: likeConst.DelteLikeSuccessMessage, - Data: deleteResponse, - } + expectedResponse := deleteResponse controller := gomock.NewController(t.T())