mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-15 12:25:50 +00:00
updatePet meyhod added in Owner !
This commit is contained in:
parent
6148ddd967
commit
1587384b43
3 changed files with 29 additions and 2 deletions
8
pom.xml
8
pom.xml
|
@ -18,7 +18,7 @@
|
|||
<properties>
|
||||
|
||||
<!-- Generic properties -->
|
||||
<java.version>17</java.version>
|
||||
<java.version>21</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<!-- Important for reproducible builds. Update using e.g. ./mvnw versions:set
|
||||
|
@ -156,6 +156,11 @@
|
|||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.gitlab.haynes</groupId>
|
||||
<artifactId>libsass-maven-plugin</artifactId>
|
||||
<version>0.2.29</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
|
@ -287,6 +292,7 @@
|
|||
<artifactId>cyclonedx-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
<licenses>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ package org.springframework.samples.petclinic.owner;
|
|||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
@ -128,7 +129,7 @@ class PetController {
|
|||
RedirectAttributes redirectAttributes) {
|
||||
|
||||
String petName = pet.getName();
|
||||
|
||||
System.out.println(pet.getId()+" SOUMEN");
|
||||
// checking if the pet name already exist for the owner
|
||||
if (StringUtils.hasText(petName)) {
|
||||
Pet existingPet = owner.getPet(petName, false);
|
||||
|
@ -147,9 +148,16 @@ class PetController {
|
|||
}
|
||||
|
||||
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