mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-16 12:55:50 +00:00
Compare commits
4 commits
92899cfe0b
...
3dc92bb2f1
Author | SHA1 | Date | |
---|---|---|---|
![]() |
3dc92bb2f1 | ||
![]() |
2aa53f929d | ||
![]() |
6328d2c9dc | ||
![]() |
7bce202762 |
3 changed files with 25 additions and 4 deletions
2
.github/dco.yml
vendored
Normal file
2
.github/dco.yml
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
require:
|
||||||
|
members: false
|
|
@ -155,7 +155,8 @@ Here is a list of them:
|
||||||
|
|
||||||
The [issue tracker](https://github.com/spring-projects/spring-petclinic/issues) is the preferred channel for bug reports, feature requests and submitting pull requests.
|
The [issue tracker](https://github.com/spring-projects/spring-petclinic/issues) is the preferred channel for bug reports, feature requests and submitting pull requests.
|
||||||
|
|
||||||
For pull requests, editor preferences are available in the [editor config](.editorconfig) for easy use in common text editors. Read more and download plugins at <https://editorconfig.org>. If you have not previously done so, please fill out and submit the [Contributor License Agreement](https://cla.pivotal.io/sign/spring).
|
For pull requests, editor preferences are available in the [editor config](.editorconfig) for easy use in common text editors. Read more and download plugins at <https://editorconfig.org>. All commits must include a __Signed-off-by__ trailer at the end of each commit message to indicate that the contributor agrees to the Developer Certificate of Origin.
|
||||||
|
For additional details, please refer to the blog post [Hello DCO, Goodbye CLA: Simplifying Contributions to Spring](https://spring.io/blog/2025/01/06/hello-dco-goodbye-cla-simplifying-contributions-to-spring).
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
|
@ -129,7 +129,7 @@ class PetController {
|
||||||
|
|
||||||
String petName = pet.getName();
|
String petName = pet.getName();
|
||||||
|
|
||||||
// checking if the pet name already exist for the owner
|
// checking if the pet name already exists for the owner
|
||||||
if (StringUtils.hasText(petName)) {
|
if (StringUtils.hasText(petName)) {
|
||||||
Pet existingPet = owner.getPet(petName, false);
|
Pet existingPet = owner.getPet(petName, false);
|
||||||
if (existingPet != null && !existingPet.getId().equals(pet.getId())) {
|
if (existingPet != null && !existingPet.getId().equals(pet.getId())) {
|
||||||
|
@ -146,10 +146,28 @@ class PetController {
|
||||||
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
|
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
|
||||||
}
|
}
|
||||||
|
|
||||||
owner.addPet(pet);
|
updatePetDetails(owner, pet);
|
||||||
this.owners.save(owner);
|
|
||||||
redirectAttributes.addFlashAttribute("message", "Pet details has been edited");
|
redirectAttributes.addFlashAttribute("message", "Pet details has been edited");
|
||||||
return "redirect:/owners/{ownerId}";
|
return "redirect:/owners/{ownerId}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the pet details if it exists or adds a new pet to the owner.
|
||||||
|
* @param owner The owner of the pet
|
||||||
|
* @param pet The pet with updated details
|
||||||
|
*/
|
||||||
|
private void updatePetDetails(Owner owner, Pet pet) {
|
||||||
|
Pet existingPet = owner.getPet(pet.getId());
|
||||||
|
if (existingPet != null) {
|
||||||
|
// Update existing pet's properties
|
||||||
|
existingPet.setName(pet.getName());
|
||||||
|
existingPet.setBirthDate(pet.getBirthDate());
|
||||||
|
existingPet.setType(pet.getType());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
owner.addPet(pet);
|
||||||
|
}
|
||||||
|
this.owners.save(owner);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue