mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-20 06:45:50 +00:00
modified the updatePet(Pet newPet) method in Owner class
This commit is contained in:
parent
98e5c6e28b
commit
9b582edb67
2 changed files with 7 additions and 8 deletions
|
@ -174,14 +174,13 @@ public class Owner extends Person {
|
||||||
|
|
||||||
public void updatePet(Pet newPet)
|
public void updatePet(Pet newPet)
|
||||||
{
|
{
|
||||||
for(int i=0 ; i<pets.size() ; i++)
|
Pet existingPet = getPet(newPet.getId());
|
||||||
|
|
||||||
|
if(existingPet != null)
|
||||||
{
|
{
|
||||||
Pet existingPet = pets.get(i);
|
existingPet.setName(newPet.getName());
|
||||||
if(existingPet.getId().equals(newPet.getId()))
|
existingPet.setBirthDate(newPet.getBirthDate());
|
||||||
{
|
existingPet.setType(newPet.getType());
|
||||||
pets.set(i,newPet);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -145,7 +145,7 @@ class PetController {
|
||||||
if (result.hasErrors()) {
|
if (result.hasErrors()) {
|
||||||
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
|
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
|
||||||
}
|
}
|
||||||
|
|
||||||
owner.updatePet(pet);
|
owner.updatePet(pet);
|
||||||
|
|
||||||
this.owners.save(owner);
|
this.owners.save(owner);
|
||||||
|
|
Loading…
Reference in a new issue