You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by da...@apache.org on 2024/05/26 12:24:36 UTC

(causeway-app-petclinic) 10/11: adds 'addPet' action

This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch v2
in repository https://gitbox.apache.org/repos/asf/causeway-app-petclinic.git

commit 4ebe45133fa5beebee8b3359286b1042ecc1bf70
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Sun May 26 12:51:17 2024 +0100

    adds 'addPet' action
---
 .../domainapp/modules/petowner/dom/petowner/PetOwner.java    | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/module-petowner/src/main/java/domainapp/modules/petowner/dom/petowner/PetOwner.java b/module-petowner/src/main/java/domainapp/modules/petowner/dom/petowner/PetOwner.java
index d845dd3..0547b0d 100644
--- a/module-petowner/src/main/java/domainapp/modules/petowner/dom/petowner/PetOwner.java
+++ b/module-petowner/src/main/java/domainapp/modules/petowner/dom/petowner/PetOwner.java
@@ -69,6 +69,7 @@ import domainapp.modules.petowner.PetOwnerModule;
 import domainapp.modules.petowner.dom.pet.Pet;
 import domainapp.modules.petowner.types.Name;
 import domainapp.modules.petowner.types.Notes;
+import domainapp.modules.petowner.types.PetName;
 import domainapp.modules.petowner.types.PhoneNumber;
 import domainapp.modules.petowner.value.EmailAddress;
 
@@ -160,6 +161,17 @@ public class PetOwner implements Comparable<PetOwner>, CalendarEventable {
     @OneToMany(mappedBy = "petOwner", cascade = CascadeType.ALL, orphanRemoval = true)
     private Set<Pet> pets = new TreeSet<>();
 
+    @Action
+    @ActionLayout(associateWith = "pets", sequence = "1")
+    public PetOwner addPet(@PetName final String name) {
+        final var pet = new Pet();
+        pet.setName(name);
+        pet.setPetOwner(this);
+        pets.add(pet);
+        return this;
+    }
+
+
     @AttributeOverrides({
             @AttributeOverride(name="name",    column=@Column(name="attachment_name")),
             @AttributeOverride(name="mimeType",column=@Column(name="attachment_mimeType")),