-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: owner not exists validation addPetToOwner #292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,9 +57,9 @@ public class OwnerRestController implements OwnersApi { | |
| private final VisitMapper visitMapper; | ||
|
|
||
| public OwnerRestController(ClinicService clinicService, | ||
| OwnerMapper ownerMapper, | ||
| PetMapper petMapper, | ||
| VisitMapper visitMapper) { | ||
| OwnerMapper ownerMapper, | ||
| PetMapper petMapper, | ||
| VisitMapper visitMapper) { | ||
| this.clinicService = clinicService; | ||
| this.ownerMapper = ownerMapper; | ||
| this.petMapper = petMapper; | ||
|
|
@@ -99,7 +99,7 @@ public ResponseEntity<OwnerDto> addOwner(OwnerFieldsDto ownerFieldsDto) { | |
| this.clinicService.saveOwner(owner); | ||
| OwnerDto ownerDto = ownerMapper.toOwnerDto(owner); | ||
| headers.setLocation(UriComponentsBuilder.newInstance() | ||
| .path("/api/owners/{id}").buildAndExpand(owner.getId()).toUri()); | ||
| .path("/api/owners/{id}").buildAndExpand(owner.getId()).toUri()); | ||
| return new ResponseEntity<>(ownerDto, headers, HttpStatus.CREATED); | ||
| } | ||
|
|
||
|
|
@@ -136,14 +136,18 @@ public ResponseEntity<OwnerDto> deleteOwner(Integer ownerId) { | |
| public ResponseEntity<PetDto> addPetToOwner(Integer ownerId, PetFieldsDto petFieldsDto) { | ||
| HttpHeaders headers = new HttpHeaders(); | ||
| Pet pet = petMapper.toPet(petFieldsDto); | ||
| Owner owner = new Owner(); | ||
| Owner owner = clinicService.findOwnerById(ownerId); | ||
|
|
||
| if (owner == null) | ||
| return new ResponseEntity<>(HttpStatus.NOT_FOUND); | ||
|
|
||
| owner.setId(ownerId); | ||
|
||
| pet.setOwner(owner); | ||
| pet.getType().setName(null); | ||
| this.clinicService.savePet(pet); | ||
| PetDto petDto = petMapper.toPetDto(pet); | ||
| headers.setLocation(UriComponentsBuilder.newInstance().path("/api/pets/{id}") | ||
| .buildAndExpand(pet.getId()).toUri()); | ||
| .buildAndExpand(pet.getId()).toUri()); | ||
|
||
| return new ResponseEntity<>(petDto, headers, HttpStatus.CREATED); | ||
| } | ||
|
|
||
|
|
@@ -175,11 +179,10 @@ public ResponseEntity<VisitDto> addVisitToOwner(Integer ownerId, Integer petId, | |
| this.clinicService.saveVisit(visit); | ||
| VisitDto visitDto = visitMapper.toVisitDto(visit); | ||
| headers.setLocation(UriComponentsBuilder.newInstance().path("/api/visits/{id}") | ||
| .buildAndExpand(visit.getId()).toUri()); | ||
| .buildAndExpand(visit.getId()).toUri()); | ||
| return new ResponseEntity<>(visitDto, headers, HttpStatus.CREATED); | ||
| } | ||
|
|
||
|
|
||
| @PreAuthorize("hasRole(@roles.OWNER_ADMIN)") | ||
| @Override | ||
| public ResponseEntity<PetDto> getOwnersPet(Integer ownerId, Integer petId) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls add/update tests for this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how can i do this ? you mean add this validation in update endpoint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check/fix tests in OwnerRestControllerTests.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i found the archive but i dont now how this works, i am learning spring boot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i added the tests , check it pls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that correct? Or do you need something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I said “tests,” not “a test.” The CI/CD is failing because one of the tests started failing after your changes. It would be good to check why this happened and fix it.
P.S.
It’s good practice to run
mvn testlocally before creating PRs - may save you some time.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, There's an error in the test from four years ago, what i need to do?

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep. this test was fine before you changed controller logic. so think about it - how this test was verify previous logic, what is changed, how you can fix it etc.