diff --git a/src/app/dto/adopt.dto.go b/src/app/dto/adopt.dto.go index 5cf4ad2..56ecaef 100644 --- a/src/app/dto/adopt.dto.go +++ b/src/app/dto/adopt.dto.go @@ -11,5 +11,5 @@ type AdoptByRequest struct { } type AdoptByResponse struct { - Success bool `json:"success" validate:"required"` + Success bool `json:"success"` } diff --git a/src/app/service/pet/pet.service.go b/src/app/service/pet/pet.service.go index 8cc0401..4362e19 100644 --- a/src/app/service/pet/pet.service.go +++ b/src/app/service/pet/pet.service.go @@ -280,7 +280,6 @@ func (s *Service) Adopt(petId string, in *dto.AdoptByRequest) (result *dto.Adopt UserId: in.UserID, PetId: in.PetID, }) - if errRes != nil { st, _ := status.FromError(errRes) log.Error(). @@ -290,25 +289,22 @@ func (s *Service) Adopt(petId string, in *dto.AdoptByRequest) (result *dto.Adopt Msg(st.Message()) switch st.Code() { case codes.NotFound: - return &dto.AdoptByResponse{ - Success: false, - }, &dto.ResponseErr{ + return nil, + &dto.ResponseErr{ StatusCode: http.StatusNotFound, Message: constant.PetNotFoundMessage, Data: nil, } case codes.Unavailable: - return &dto.AdoptByResponse{ - Success: false, - }, &dto.ResponseErr{ + return nil, + &dto.ResponseErr{ StatusCode: http.StatusServiceUnavailable, Message: constant.UnavailableServiceMessage, Data: nil, } default: - return &dto.AdoptByResponse{ - Success: false, - }, &dto.ResponseErr{ + return nil, + &dto.ResponseErr{ StatusCode: http.StatusServiceUnavailable, Message: constant.InternalErrorMessage, Data: nil, diff --git a/src/app/service/pet/pet.service_test.go b/src/app/service/pet/pet.service_test.go index 797af40..5705c12 100644 --- a/src/app/service/pet/pet.service_test.go +++ b/src/app/service/pet/pet.service_test.go @@ -539,40 +539,34 @@ func (t *PetServiceTest) TestAdoptSuccess() { func (t *PetServiceTest) TestAdoptNotFoundError() { protoReq := t.AdoptReq - protoResp := &petproto.AdoptPetResponse{ - Success: false, - } clientErr := status.Error(codes.NotFound, constant.PetNotFoundMessage) expected := t.NotFoundErr client := &petmock.PetClientMock{} - client.On("AdoptPet", protoReq).Return(protoResp, clientErr) + client.On("AdoptPet", protoReq).Return(nil, clientErr) svc := NewService(client) actual, err := svc.Adopt(t.Pet.Id, t.AdoptDto) - assert.Equal(t.T(), &dto.AdoptByResponse{Success: false}, actual) + assert.Nil(t.T(), actual) assert.Equal(t.T(), expected, err) } func (t *PetServiceTest) TestAdoptUnavailableServiceError() { protoReq := t.AdoptReq - protoResp := &petproto.AdoptPetResponse{ - Success: false, - } clientErr := status.Error(codes.Unavailable, constant.UnavailableServiceMessage) expected := t.UnavailableServiceErr client := &petmock.PetClientMock{} - client.On("AdoptPet", protoReq).Return(protoResp, clientErr) + client.On("AdoptPet", protoReq).Return(nil, clientErr) svc := NewService(client) actual, err := svc.Adopt(t.Pet.Id, t.AdoptDto) - assert.Equal(t.T(), &dto.AdoptByResponse{Success: false}, actual) + assert.Nil(t.T(), actual) assert.Equal(t.T(), expected, err) }