Skip to content

Commit

Permalink
fix: like handler use lighter success resp
Browse files Browse the repository at this point in the history
  • Loading branch information
bookpanda committed Jan 9, 2024
1 parent 71c3175 commit 797e5a4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 38 deletions.
6 changes: 0 additions & 6 deletions src/app/dto/common.dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
19 changes: 3 additions & 16 deletions src/app/handler/like/like.handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand All @@ -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
}
19 changes: 3 additions & 16 deletions src/app/handler/like/like.handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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())

Expand Down

0 comments on commit 797e5a4

Please sign in to comment.