Skip to content

Commit

Permalink
fix: pet svc delete return nil
Browse files Browse the repository at this point in the history
  • Loading branch information
bookpanda committed Jan 5, 2024
1 parent 3ac9671 commit 3059615
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
31 changes: 13 additions & 18 deletions src/app/service/pet/pet.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/app/service/pet/pet.service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down

0 comments on commit 3059615

Please sign in to comment.