From 3059615aabe49be0149b7167134f4646aa999a51 Mon Sep 17 00:00:00 2001 From: Idhibhat Pankam Date: Fri, 5 Jan 2024 23:28:31 +0700 Subject: [PATCH] fix: pet svc delete return nil --- src/app/service/pet/pet.service.go | 31 +++++++++++-------------- src/app/service/pet/pet.service_test.go | 4 ++-- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/app/service/pet/pet.service.go b/src/app/service/pet/pet.service.go index fe0b4c7..6cfe664 100644 --- a/src/app/service/pet/pet.service.go +++ b/src/app/service/pet/pet.service.go @@ -196,29 +196,24 @@ func (s *Service) Delete(id string) (result *dto.DeleteResponse, err *dto.Respon Msg(st.Message()) switch st.Code() { case codes.NotFound: - return &dto.DeleteResponse{ - Success: false, - }, &dto.ResponseErr{ - StatusCode: http.StatusNotFound, - Message: constant.PetNotFoundMessage, - Data: nil, - } + return nil, &dto.ResponseErr{ + StatusCode: http.StatusNotFound, + Message: constant.PetNotFoundMessage, + Data: nil, + } case codes.Unavailable: - return &dto.DeleteResponse{ - Success: false, - }, &dto.ResponseErr{ - StatusCode: http.StatusServiceUnavailable, - Message: constant.UnavailableServiceMessage, - Data: nil, - } - } - return &dto.DeleteResponse{ - Success: false, - }, &dto.ResponseErr{ + return nil, &dto.ResponseErr{ + StatusCode: http.StatusServiceUnavailable, + Message: constant.UnavailableServiceMessage, + Data: nil, + } + default: + return nil, &dto.ResponseErr{ StatusCode: http.StatusInternalServerError, Message: constant.InternalErrorMessage, Data: nil, } + } } return &dto.DeleteResponse{ Success: res.Success, diff --git a/src/app/service/pet/pet.service_test.go b/src/app/service/pet/pet.service_test.go index abab448..aaa2b73 100644 --- a/src/app/service/pet/pet.service_test.go +++ b/src/app/service/pet/pet.service_test.go @@ -434,7 +434,7 @@ func (t *PetServiceTest) TestDeleteNotFound() { svc := NewService(client) actual, err := svc.Delete(t.Pet.Id) - assert.Equal(t.T(), &dto.DeleteResponse{Success: false}, actual) + assert.Nil(t.T(), actual) assert.Equal(t.T(), expected, err) } @@ -455,7 +455,7 @@ func (t *PetServiceTest) TestDeleteServiceUnavailableError() { svc := NewService(client) actual, err := svc.Delete(t.Pet.Id) - assert.Equal(t.T(), &dto.DeleteResponse{Success: false}, actual) + assert.Nil(t.T(), actual) assert.Equal(t.T(), expected, err) }