From eee02473154b41fdc28ee7391b49e454a4b2bc78 Mon Sep 17 00:00:00 2001 From: nidhi-vm Date: Thu, 19 Jun 2025 15:31:17 -0400 Subject: [PATCH] Updating using GitHub API 2025-06-19-15:31 --- .../samples/petclinic/owner/PetController.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/springframework/samples/petclinic/owner/PetController.java b/src/main/java/org/springframework/samples/petclinic/owner/PetController.java index 3234e39d6..44b1f3637 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/PetController.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/PetController.java @@ -59,10 +59,8 @@ class PetController { @ModelAttribute("owner") public Owner findOwner(@PathVariable("ownerId") int ownerId) { - Optional optionalOwner = this.owners.findById(ownerId); - Owner owner = optionalOwner.orElseThrow(() -> new IllegalArgumentException( + return this.owners.findById(ownerId).orElseThrow(() -> new IllegalArgumentException( "Owner not found with id: " + ownerId + ". Please ensure the ID is correct ")); - return owner; } @ModelAttribute("pet") @@ -73,8 +71,7 @@ class PetController { return new Pet(); } - Optional optionalOwner = this.owners.findById(ownerId); - Owner owner = optionalOwner.orElseThrow(() -> new IllegalArgumentException( + Owner owner = this.owners.findById(ownerId).orElseThrow(() -> new IllegalArgumentException( "Owner not found with id: " + ownerId + ". Please ensure the ID is correct ")); return owner.getPet(petId); } @@ -170,4 +167,4 @@ class PetController { this.owners.save(owner); } -} +} \ No newline at end of file