This commit is contained in:
Soumen Mallick 2024-12-22 07:50:23 +00:00 committed by GitHub
commit 0a0741026f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 47 additions and 3 deletions

View file

@ -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>

View file

@ -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;
}
}
}
}

View file

@ -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;
@ -42,7 +43,7 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
*/
@Controller
@RequestMapping("/owners/{ownerId}")
class PetController {
class privatePetController {
private static final String VIEWS_PETS_CREATE_OR_UPDATE_FORM = "pets/createOrUpdatePetForm";
@ -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);
@ -146,10 +147,34 @@ class PetController {
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
}
<<<<<<< HEAD
owner.addPet(pet);
owner.updatePet(pet);
||||||| 6148ddd
owner.addPet(pet);
=======
//owner.addPet(pet);
List<Pet> petlist = owner.getPets();
for(int i=0 ; i<petlist.size() ; i++)
{
if(petlist.get(i).getId().equals(pet.getId()))
{
petlist.set(i,pet);
break;
}
}
>>>>>>> 588fd808f860ff0896eb2e4cb841f8cacd19855b
this.owners.save(owner);
redirectAttributes.addFlashAttribute("message", "Pet details has been edited");
return "redirect:/owners/{ownerId}";
}
}