Skip to content

Commit

Permalink
fix: pet handler lighter sucess resp
Browse files Browse the repository at this point in the history
  • Loading branch information
bookpanda committed Jan 9, 2024
1 parent 974c192 commit 71c3175
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 72 deletions.
43 changes: 7 additions & 36 deletions src/app/handler/pet/pet.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"
petconst "github.com/isd-sgcu/johnjud-gateway/src/constant/pet"
imageSvc "github.com/isd-sgcu/johnjud-gateway/src/pkg/service/image"
petSvc "github.com/isd-sgcu/johnjud-gateway/src/pkg/service/pet"
)
Expand Down Expand Up @@ -40,11 +39,7 @@ func (h *Handler) FindAll(c router.IContext) {
return
}

c.JSON(http.StatusOK, dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: petconst.FindAllPetSuccessMessage,
Data: response,
})
c.JSON(http.StatusOK, response)
return
}

Expand Down Expand Up @@ -77,11 +72,7 @@ func (h *Handler) FindOne(c router.IContext) {
return
}

c.JSON(http.StatusOK, dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: petconst.FindOnePetSuccessMessage,
Data: response,
})
c.JSON(http.StatusOK, response)
return
}

Expand Down Expand Up @@ -128,11 +119,7 @@ func (h *Handler) Create(c router.IContext) {
return
}

c.JSON(http.StatusCreated, dto.ResponseSuccess{
StatusCode: http.StatusCreated,
Message: petconst.CreatePetSuccessMessage,
Data: response,
})
c.JSON(http.StatusCreated, response)
return
}

Expand Down Expand Up @@ -191,11 +178,7 @@ func (h *Handler) Update(c router.IContext) {
return
}

c.JSON(http.StatusOK, dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: petconst.UpdatePetSuccessMessage,
Data: pet,
})
c.JSON(http.StatusOK, pet)
return
}

Expand Down Expand Up @@ -254,11 +237,7 @@ func (h *Handler) ChangeView(c router.IContext) {
return
}

c.JSON(http.StatusOK, dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: petconst.ChangeViewPetSuccessMessage,
Data: res,
})
c.JSON(http.StatusOK, res)
return
}

Expand Down Expand Up @@ -291,11 +270,7 @@ func (h *Handler) Delete(c router.IContext) {
return
}

c.JSON(http.StatusOK, dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: petconst.DeletePetSuccessMessage,
Data: res,
})
c.JSON(http.StatusOK, res)
return
}

Expand Down Expand Up @@ -354,10 +329,6 @@ func (h *Handler) Adopt(c router.IContext) {
return
}

c.JSON(http.StatusOK, dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: petconst.AdoptPetSuccessMessage,
Data: res,
})
c.JSON(http.StatusOK, res)
return
}
43 changes: 7 additions & 36 deletions src/app/handler/pet/pet.handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

errConst "github.com/isd-sgcu/johnjud-gateway/src/app/constant"
utils "github.com/isd-sgcu/johnjud-gateway/src/app/utils/pet"
petConst "github.com/isd-sgcu/johnjud-gateway/src/constant/pet"
petProto "github.com/isd-sgcu/johnjud-go-proto/johnjud/backend/pet/v1"
imgProto "github.com/isd-sgcu/johnjud-go-proto/johnjud/file/image/v1"

Expand Down Expand Up @@ -131,11 +130,7 @@ func (t *PetHandlerTest) SetupTest() {

func (t *PetHandlerTest) TestFindAllSuccess() {
findAllResponse := utils.ProtoToDtoList(t.Pets, t.ImagesList)
expectedResponse := dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: petConst.FindAllPetSuccessMessage,
Data: findAllResponse,
}
expectedResponse := findAllResponse

controller := gomock.NewController(t.T())

Expand All @@ -153,11 +148,7 @@ func (t *PetHandlerTest) TestFindAllSuccess() {

func (t *PetHandlerTest) TestFindOneSuccess() {
findOneResponse := utils.ProtoToDto(t.Pet, t.Images)
expectedResponse := dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: petConst.FindOnePetSuccessMessage,
Data: findOneResponse,
}
expectedResponse := findOneResponse

controller := gomock.NewController(t.T())

Expand Down Expand Up @@ -212,11 +203,7 @@ func (t *PetHandlerTest) TestFindOneGrpcErr() {

func (t *PetHandlerTest) TestCreateSuccess() {
createResponse := utils.ProtoToDto(t.Pet, t.Images)
expectedResponse := dto.ResponseSuccess{
StatusCode: http.StatusCreated,
Message: petConst.CreatePetSuccessMessage,
Data: createResponse,
}
expectedResponse := createResponse

controller := gomock.NewController(t.T())

Expand Down Expand Up @@ -255,11 +242,7 @@ func (t *PetHandlerTest) TestCreateGrpcErr() {

func (t *PetHandlerTest) TestUpdateSuccess() {
updateResponse := utils.ProtoToDto(t.Pet, t.Images)
expectedResponse := dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: petConst.UpdatePetSuccessMessage,
Data: updateResponse,
}
expectedResponse := updateResponse

controller := gomock.NewController(t.T())

Expand Down Expand Up @@ -322,11 +305,7 @@ func (t *PetHandlerTest) TestDeleteSuccess() {
deleteResponse := &dto.DeleteResponse{
Success: true,
}
expectedResponse := dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: petConst.DeletePetSuccessMessage,
Data: deleteResponse,
}
expectedResponse := deleteResponse

controller := gomock.NewController(t.T())

Expand Down Expand Up @@ -386,11 +365,7 @@ func (t *PetHandlerTest) TestChangeViewSuccess() {
changeViewResponse := &dto.ChangeViewPetResponse{
Success: true,
}
expectedResponse := dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: petConst.ChangeViewPetSuccessMessage,
Data: changeViewResponse,
}
expectedResponse := changeViewResponse

controller := gomock.NewController(t.T())

Expand Down Expand Up @@ -457,11 +432,7 @@ func (t *PetHandlerTest) TestAdoptSuccess() {
adoptByResponse := &dto.AdoptByResponse{
Success: true,
}
expectedResponse := dto.ResponseSuccess{
StatusCode: http.StatusOK,
Message: petConst.AdoptPetSuccessMessage,
Data: adoptByResponse,
}
expectedResponse := adoptByResponse

controller := gomock.NewController(t.T())

Expand Down

0 comments on commit 71c3175

Please sign in to comment.