Skip to content

Commit

Permalink
Validation of unique pet name moved to Clinic Service
Browse files Browse the repository at this point in the history
  • Loading branch information
japarejo committed Feb 12, 2020
1 parent f3b5294 commit bed2364
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
*
* @author japarejo
*/
public class DuplicatedPetNameException extends RuntimeException{
public class DuplicatedPetNameException extends Exception{

}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ public String processUpdateForm(@Valid Pet pet, BindingResult result, Owner owne
else {
Pet petToUpdate=this.clinicService.findPetById(petId);
BeanUtils.copyProperties(pet, petToUpdate, "id","owner","visits");
try {
this.clinicService.savePet(petToUpdate);
} catch (DuplicatedPetNameException ex) {
result.rejectValue("name", "duplicate", "already exists");
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
}
return "redirect:/owners/{ownerId}";
}
}
Expand Down

0 comments on commit bed2364

Please sign in to comment.