mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-15 20:35:49 +00:00
added updatePet in Owner
This commit is contained in:
parent
6148ddd967
commit
4aad661973
2 changed files with 16 additions and 1 deletions
|
@ -172,4 +172,17 @@ public class Owner extends Person {
|
|||
pet.addVisit(visit);
|
||||
}
|
||||
|
||||
public void updatePet(Pet newPet)
|
||||
{
|
||||
for(int i=0 ; i<pets.size() ; i++)
|
||||
{
|
||||
Pet existingPet = pets.get(i);
|
||||
if(existingPet.getId().equals(newPet.getId()))
|
||||
{
|
||||
pets.set(i,newPet);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -146,7 +146,9 @@ class PetController {
|
|||
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
owner.addPet(pet);
|
||||
//owner.addPet(pet);
|
||||
owner.updatePet(pet);
|
||||
|
||||
this.owners.save(owner);
|
||||
redirectAttributes.addFlashAttribute("message", "Pet details has been edited");
|
||||
return "redirect:/owners/{ownerId}";
|
||||
|
|
Loading…
Reference in a new issue