Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pet update fix #1753

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -287,6 +292,7 @@
<artifactId>cyclonedx-maven-plugin</artifactId>
</plugin>


</plugins>
</build>
<licenses>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,17 @@ public void addVisit(Integer petId, Visit visit) {
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;
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.time.LocalDate;
import java.util.Collection;
import java.util.List;
import java.util.Optional;

import org.springframework.stereotype.Controller;
Expand All @@ -42,7 +43,7 @@
*/
@Controller
@RequestMapping("/owners/{ownerId}")
class PetController {
class privatePetController {

private static final String VIEWS_PETS_CREATE_OR_UPDATE_FORM = "pets/createOrUpdatePetForm";

Expand Down Expand Up @@ -128,7 +129,7 @@ public String processUpdateForm(Owner owner, @Valid Pet pet, BindingResult resul
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);
Expand All @@ -146,10 +147,34 @@ public String processUpdateForm(Owner owner, @Valid Pet pet, BindingResult resul
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
}

<<<<<<< HEAD
owner.addPet(pet);
owner.updatePet(pet);

||||||| 6148ddd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not ready to merge

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






}