From 2fd02a9aa35862c678e9fe4501678e1a321c4bf4 Mon Sep 17 00:00:00 2001 From: Ashish Sam Date: Tue, 26 Sep 2023 04:04:40 +0530 Subject: [PATCH 1/8] Create dynamic form component for adding persons to family --- .../Forms/AddPersonInFamilyForm.vue | 58 +++++ Tithe-Vue/src/components/Forms/PersonForm.vue | 180 ++++++++++++++ .../FamilyByParishSingleSelectBox.vue | 72 ++++++ .../SearchBoxes/RelationSingleSelectBox.vue | 62 +++++ Tithe-Vue/src/views/FamilyView.vue | 231 +++++------------- Tithe-Vue/src/views/KoottaymaView.vue | 7 +- Tithe-Vue/src/views/PersonView.vue | 2 +- 7 files changed, 437 insertions(+), 175 deletions(-) create mode 100644 Tithe-Vue/src/components/Forms/AddPersonInFamilyForm.vue create mode 100644 Tithe-Vue/src/components/Forms/PersonForm.vue create mode 100644 Tithe-Vue/src/components/SearchBoxes/FamilyByParishSingleSelectBox.vue create mode 100644 Tithe-Vue/src/components/SearchBoxes/RelationSingleSelectBox.vue diff --git a/Tithe-Vue/src/components/Forms/AddPersonInFamilyForm.vue b/Tithe-Vue/src/components/Forms/AddPersonInFamilyForm.vue new file mode 100644 index 0000000..92c2b41 --- /dev/null +++ b/Tithe-Vue/src/components/Forms/AddPersonInFamilyForm.vue @@ -0,0 +1,58 @@ + + + diff --git a/Tithe-Vue/src/components/Forms/PersonForm.vue b/Tithe-Vue/src/components/Forms/PersonForm.vue new file mode 100644 index 0000000..2c483f4 --- /dev/null +++ b/Tithe-Vue/src/components/Forms/PersonForm.vue @@ -0,0 +1,180 @@ + + + + + diff --git a/Tithe-Vue/src/components/SearchBoxes/FamilyByParishSingleSelectBox.vue b/Tithe-Vue/src/components/SearchBoxes/FamilyByParishSingleSelectBox.vue new file mode 100644 index 0000000..b608281 --- /dev/null +++ b/Tithe-Vue/src/components/SearchBoxes/FamilyByParishSingleSelectBox.vue @@ -0,0 +1,72 @@ + + + diff --git a/Tithe-Vue/src/components/SearchBoxes/RelationSingleSelectBox.vue b/Tithe-Vue/src/components/SearchBoxes/RelationSingleSelectBox.vue new file mode 100644 index 0000000..073ef78 --- /dev/null +++ b/Tithe-Vue/src/components/SearchBoxes/RelationSingleSelectBox.vue @@ -0,0 +1,62 @@ + + + diff --git a/Tithe-Vue/src/views/FamilyView.vue b/Tithe-Vue/src/views/FamilyView.vue index 5253c16..47ff334 100644 --- a/Tithe-Vue/src/views/FamilyView.vue +++ b/Tithe-Vue/src/views/FamilyView.vue @@ -16,9 +16,11 @@ import { mdiTableLarge, } from "@mdi/js"; -import SearchBox from "@/components/SearchBox.vue"; +import AddPersonInFamilyForm from "@/components/Forms/AddPersonInFamilyForm.vue"; import ForaneSingleSelectBox from "@/components/SearchBoxes/ForaneSingleSelectBox.vue"; import ParishByForaneSingleSelectBox from "@/components/SearchBoxes/ParishByForaneSingleSelectBox.vue"; +import FamilyByParishSingleSelectBox from "@/components/SearchBoxes/FamilyByParishSingleSelectBox.vue"; +import KoottaymaByParishSingleSelectBox from "@/components/SearchBoxes/KoottaymaByParishSingleSelectBox.vue"; import LayoutAuthenticated from "@/layouts/LayoutAuthenticated.vue"; import SectionMain from "@/components/SectionMain.vue"; import FormField from "@/components/FormField.vue"; @@ -37,11 +39,7 @@ import RemoveEntityDisclosure from "@/components/RemoveEntityDisclosure.vue"; import TableTabs from "@/components/TableTabs.vue"; import { - familyAllForaneListQuery, - familyAllParishListQuery, - familyAllFamilyListQuery, familyPageActiveEnityCountQuery, - familyAllKoottaymaListQuery, familyPageActivePersonTableQuery, } from "@/externalized-data/graphqlQueries"; import { @@ -81,69 +79,16 @@ const forane = ref(); const parish = ref(); const family = ref(); -const ACTIVE_FORANE_LIST_QUERY = gql` - ${familyAllForaneListQuery} -`; - -const { - result: activeForaneList, - load: activeForaneListLoad, - refetch: activeForaneListRefetch, -} = useLazyQuery(ACTIVE_FORANE_LIST_QUERY); -activeForaneListLoad(); -const loadForanes = (query, setOptions) => { - setOptions( - activeForaneList.value?.getAllForanes?.map((entity) => { - return { - id: entity.foraneId, - label: entity.foraneName, - }; - }) ?? [] - ); +const changeInForane = (entity) => { + forane.value = entity; }; -const ACTIVE_PARISH_BY_FORANE_LIST_QUERY = gql` - ${familyAllParishListQuery} -`; - -const { - result: activeParishList, - load: activeParishListLoad, - refetch: activeParishListRefetch, -} = useLazyQuery(ACTIVE_PARISH_BY_FORANE_LIST_QUERY, () => ({ - foraneId: forane.value.id, -})); -const loadParishesByForane = (query, setOptions) => { - setOptions( - activeParishList.value?.getAllParishesByForane?.map((entity) => { - return { - id: entity.parishId, - label: entity.parishName, - }; - }) ?? [] - ); +const changeInParish = (entity) => { + parish.value = entity; }; -const ACTIVE_FAMILY_BY_PARISH_LIST_QUERY = gql` - ${familyAllFamilyListQuery} -`; - -const { - result: activeFamilyList, - load: activeFamilyListLoad, - refetch: activeFamilyListRefetch, -} = useLazyQuery(ACTIVE_FAMILY_BY_PARISH_LIST_QUERY, () => ({ - parishId: parish.value.id, -})); -const loadFamiliesByParish = (query, setOptions) => { - setOptions( - activeFamilyList.value?.getAllFamiliesByParish?.map((entity) => { - return { - id: entity.familyId, - label: entity.familyName, - }; - }) ?? [] - ); +const changeInFamily = (entity) => { + family.value = entity; }; // Entity Count in Family Page @@ -165,14 +110,6 @@ const activePersonCount = computed( () => activeEntityByFamilyCount.value?.getPersonCountByFamily ?? 0 ); -watch(forane, () => { - activeParishListLoad(); -}); - -watch(parish, () => { - activeFamilyListLoad(); -}); - watch(family, () => { activeEntityByFamilyCountEnabled.value = true; }); @@ -197,56 +134,20 @@ const formForane = ref(); // Form Parish Search Box const formParish = ref(); -const { - result: activeFormParishList, - load: activeFormParishListLoad, - refetch: activeFormParishListRefetch, -} = useLazyQuery(ACTIVE_PARISH_BY_FORANE_LIST_QUERY, () => ({ - foraneId: formForane.value.id, -})); -const loadFormParishesByForane = (query, setOptions) => { - setOptions( - activeFormParishList.value?.getAllParishesByForane?.map((entity) => { - return { - id: entity.parishId, - label: entity.parishName, - }; - }) ?? [] - ); -}; - // Form Koottayma Search Box const formKoottayma = ref(); -const ACTIVE_KOOTTAYMA_BY_PARISH_LIST_QUERY = gql` - ${familyAllKoottaymaListQuery} -`; - -const { - result: activeFormKoottaymaList, - load: activeFormKoottaymaListLoad, - refetch: activeFormKoottaymaListRefetch, -} = useLazyQuery(ACTIVE_KOOTTAYMA_BY_PARISH_LIST_QUERY, () => ({ - parishId: formParish.value.id, -})); -const loadFormKoottaymasByParish = (query, setOptions) => { - setOptions( - activeFormKoottaymaList.value?.getAllKoottaymasByParish?.map((entity) => { - return { - id: entity.koottaymaId, - label: entity.koottaymaName, - }; - }) ?? [] - ); +const changeInFormForane = (entity) => { + formForane.value = entity; }; -watch(formForane, () => { - activeFormParishListLoad(); -}); +const changeInFormParish = (entity) => { + formParish.value = entity; +}; -watch(formParish, () => { - activeFormKoottaymaListLoad(); -}); +const changeInFormKoottayma = (entity) => { + formKoottayma.value = entity; +}; watch(formKoottayma, (value) => { createFamilyForm.koottaymaId = value.id; @@ -404,32 +305,22 @@ const getActivePersonRows = computed(() => {
- - - - - - - - + + + + + + + + +
@@ -451,6 +342,7 @@ const getActivePersonRows = computed(() => { v-model="createFamilyForm.familyName" type="text" :icon="mdiAccountMultiple" + :borderless="true" placeholder="Shalom House" /> @@ -460,37 +352,29 @@ const getActivePersonRows = computed(() => { v-model="createFamilyForm.address.buildingName" /> --> - - - - - - - - - + + + + @@ -498,9 +382,10 @@ const getActivePersonRows = computed(() => { ref="addressFormComponent" @address-form-change="changeInAddressFormData" /> + @@ -619,4 +504,12 @@ const getActivePersonRows = computed(() => { .baseButtonStyle { width: 100%; } + +.multipleSelectAddressBox :deep(.multiselect-theme) { + --ms-bg: #1e293b; + --ms-dropdown-bg: #1e293b; + --ms-dropdown-border-color: #1e293b; + + --ms-py: 0.757rem; +} diff --git a/Tithe-Vue/src/views/KoottaymaView.vue b/Tithe-Vue/src/views/KoottaymaView.vue index 8bb89aa..5962586 100644 --- a/Tithe-Vue/src/views/KoottaymaView.vue +++ b/Tithe-Vue/src/views/KoottaymaView.vue @@ -20,7 +20,6 @@ import { import ForaneSingleSelectBox from "@/components/SearchBoxes/ForaneSingleSelectBox.vue"; import ParishByForaneSingleSelectBox from "@/components/SearchBoxes/ParishByForaneSingleSelectBox.vue"; import KoottaymaByParishSingleSelectBox from "@/components/SearchBoxes/KoottaymaByParishSingleSelectBox.vue"; -import SearchBox from "@/components/SearchBox.vue"; import LayoutAuthenticated from "@/layouts/LayoutAuthenticated.vue"; import SectionMain from "@/components/SectionMain.vue"; import FormField from "@/components/FormField.vue"; @@ -38,9 +37,6 @@ import RemoveEntityDisclosure from "@/components/RemoveEntityDisclosure.vue"; import TableTabs from "@/components/TableTabs.vue"; import { - koottaymaAllForaneListQuery, - koottaymaAllParishListQuery, - koottaymaAllKoottaymaListQuery, koottaymaPageActiveEnityCountQuery, koottaymaPageActiveFamilyTableQuery, koottaymaPageActivePersonTableQuery, @@ -336,6 +332,7 @@ const getActivePersonRows = computed(() => { v-model="createKoottaymaForm.koottaymaName" type="text" :icon="mdiHandsPray" + :borderless="true" placeholder="St. George Koottayma" /> @@ -355,7 +352,7 @@ const getActivePersonRows = computed(() => { diff --git a/Tithe-Vue/src/views/PersonView.vue b/Tithe-Vue/src/views/PersonView.vue index 629e5a6..35749ad 100644 --- a/Tithe-Vue/src/views/PersonView.vue +++ b/Tithe-Vue/src/views/PersonView.vue @@ -569,7 +569,7 @@ onMounted(() => { From ef8b007a8fcba4fc0cc19cf46466e4f413489bc7 Mon Sep 17 00:00:00 2001 From: Ashish Sam T George Date: Fri, 29 Sep 2023 02:26:44 +0530 Subject: [PATCH 2/8] Use Builder pattern for building Person and Tithe Entities - Create Builder class - Create Head of family and family members, when a new family is created - Create a new Graphql schema for Person mutation input through family - Removed @NotNull constraint in PersonMutationInput for family field --- .../java/com/tithe/entity/FamilyEntity.java | 13 ++- .../java/com/tithe/entity/PersonBuilder.java | 107 ++++++++++++++++++ .../java/com/tithe/entity/PersonEntity.java | 5 +- .../java/com/tithe/entity/TitheBuilder.java | 98 ++++++++++++++++ .../com/tithe/model/FamilyMutationInput.java | 7 ++ .../com/tithe/model/PersonMutationInput.java | 4 +- .../mutation/FamilyMutationService.java | 45 ++++++-- .../mutation/PersonMutationService.java | 106 ++++++++++++----- .../mutation/TitheMutationService.java | 4 +- .../service/query/PersonQueryService.java | 1 + .../service/query/TitheQueryService.java | 35 ------ .../resources/graphql/types/Family.graphqls | 3 + .../resources/graphql/types/Person.graphqls | 14 +++ 13 files changed, 364 insertions(+), 78 deletions(-) create mode 100755 Tithe-Spring/src/main/java/com/tithe/entity/PersonBuilder.java create mode 100755 Tithe-Spring/src/main/java/com/tithe/entity/TitheBuilder.java diff --git a/Tithe-Spring/src/main/java/com/tithe/entity/FamilyEntity.java b/Tithe-Spring/src/main/java/com/tithe/entity/FamilyEntity.java index 207fec2..36de3a9 100755 --- a/Tithe-Spring/src/main/java/com/tithe/entity/FamilyEntity.java +++ b/Tithe-Spring/src/main/java/com/tithe/entity/FamilyEntity.java @@ -3,6 +3,7 @@ */ package com.tithe.entity; + import java.util.List; import jakarta.persistence.CascadeType; @@ -13,6 +14,7 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; +import jakarta.persistence.OneToOne; import jakarta.persistence.Table; import jakarta.persistence.UniqueConstraint; import jakarta.validation.constraints.NotBlank; @@ -21,6 +23,7 @@ import lombok.Data; import lombok.NoArgsConstructor; + /** * @author Ashish Sam T George * @@ -29,7 +32,8 @@ @AllArgsConstructor @NoArgsConstructor @Entity -@Table(name = "family_table", uniqueConstraints = @UniqueConstraint(columnNames = {"familyName", "phone"})) +@Table(name = "family_table", uniqueConstraints = @UniqueConstraint(columnNames = { "familyName", + "head_of_family_id", "phone" })) public class FamilyEntity { @Id @@ -51,7 +55,12 @@ public class FamilyEntity { @JoinColumn(name = "koottayma_id") private KoottaymaEntity koottayma; - @OneToMany(mappedBy = "family") + @NotNull(message = "Head of Family does not exist") + @OneToOne(cascade = CascadeType.PERSIST) + @JoinColumn(name = "head_of_family_id") + private PersonEntity headOfFamily; + + @OneToMany(cascade = CascadeType.PERSIST, mappedBy = "family") private List persons; @OneToMany(mappedBy = "family") diff --git a/Tithe-Spring/src/main/java/com/tithe/entity/PersonBuilder.java b/Tithe-Spring/src/main/java/com/tithe/entity/PersonBuilder.java new file mode 100755 index 0000000..2d03d04 --- /dev/null +++ b/Tithe-Spring/src/main/java/com/tithe/entity/PersonBuilder.java @@ -0,0 +1,107 @@ +/** + * + */ +package com.tithe.entity; + + +import java.time.LocalDate; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; + +import com.tithe.model.GenderEnum; +import com.tithe.utils.ObjectValidation; + + +/** + * @author Ashish Sam T George + * + */ +public class PersonBuilder { + + private Long personId; + private String baptismName; + private String personName; + private FamilyEntity family; + private RelationEntity relation; + private GenderEnum gender; + private LocalDate dob; + private String phone; + private List tithes; + private Boolean moved = false; + private List educations; + private List occupations; + private Boolean active = true; + + public PersonBuilder personId(Long personId) { + this.personId = personId; + return this; + } + + public PersonBuilder baptismName(String baptismName) { + this.baptismName = baptismName; + return this; + } + + public PersonBuilder personName(String personName) { + this.personName = personName; + return this; + } + + public PersonBuilder family(FamilyEntity family) { + this.family = family; + return this; + } + + public PersonBuilder relation(RelationEntity relation) { + this.relation = relation; + return this; + } + + public PersonBuilder gender(GenderEnum gender) { + this.gender = gender; + return this; + } + + public PersonBuilder dob(LocalDate dob) { + this.dob = dob; + return this; + } + + public PersonBuilder phone(String phone) { + this.phone = phone; + return this; + } + +// public PersonBuilder tithes(List tithes) { +// this.tithes = tithes; +// return this; +// } + + public PersonBuilder moved(Boolean moved) { + this.moved = moved; + return this; + } + + public PersonBuilder educations(List educations) { + this.educations = educations; + return this; + } + + public PersonBuilder occupations(List occupations) { + this.occupations = occupations; + return this; + } + + public PersonBuilder active(Boolean active) { + this.active = active; + return this; + } + + public PersonEntity build() { + PersonEntity person = new PersonEntity(personId, baptismName, personName, family, relation, gender, dob, phone, + tithes, moved, educations, occupations, active); + return person; + } + +} diff --git a/Tithe-Spring/src/main/java/com/tithe/entity/PersonEntity.java b/Tithe-Spring/src/main/java/com/tithe/entity/PersonEntity.java index fbad0e5..1e63e9e 100755 --- a/Tithe-Spring/src/main/java/com/tithe/entity/PersonEntity.java +++ b/Tithe-Spring/src/main/java/com/tithe/entity/PersonEntity.java @@ -53,8 +53,9 @@ public class PersonEntity { @NotBlank(message = "Name of Person is empty or null") private String personName; - @NotNull(message = "Family does not exist") - @ManyToOne(cascade = CascadeType.PERSIST) +// @NotNull(message = "Family does not exist") +// @ManyToOne(cascade = CascadeType.PERSIST) + @ManyToOne @JoinColumn(name = "family_id") private FamilyEntity family; diff --git a/Tithe-Spring/src/main/java/com/tithe/entity/TitheBuilder.java b/Tithe-Spring/src/main/java/com/tithe/entity/TitheBuilder.java new file mode 100755 index 0000000..0c54423 --- /dev/null +++ b/Tithe-Spring/src/main/java/com/tithe/entity/TitheBuilder.java @@ -0,0 +1,98 @@ +/** + * + */ +package com.tithe.entity; + + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + +import com.tithe.model.TitheMutationInput; + + +/** + * @author Ashish Sam T George + * + */ +public class TitheBuilder { + + private Long titheId; + private Double titheAmount; + private PersonEntity person; + private FamilyEntity family; + private KoottaymaEntity koottayma; + private ParishEntity parish; + private ForaneEntity forane; + private LocalDate timeStamp; + + public TitheBuilder titheId(Long titheId) { + this.titheId = titheId; + return this; + } + + public TitheBuilder titheAmount(Double titheAmount) { + this.titheAmount = titheAmount; + return this; + } + + public TitheBuilder person(PersonEntity person) { + this.person = person; + return this; + } + + public TitheBuilder family(FamilyEntity family) { + this.family = family; + return this; + } + + public TitheBuilder koottayma(KoottaymaEntity koottayma) { + this.koottayma = koottayma; + return this; + } + + public TitheBuilder parish(ParishEntity parish) { + this.parish = parish; + return this; + } + + public TitheBuilder forane(ForaneEntity forane) { + this.forane = forane; + return this; + } + + public TitheBuilder timeStamp(LocalDate timeStamp) { + this.timeStamp = timeStamp; + return this; + } + + public TitheEntity build() { + TitheEntity tithe = new TitheEntity(titheId, titheAmount, person, family, koottayma, parish, + forane, timeStamp); + return tithe; + } + + public List buildTithe(PersonEntity person, + List titheMutationInputs) { + List tithes = new ArrayList<>(); + if (titheMutationInputs != null && titheMutationInputs.size() != 0) { +// objectValidation.validateObjects(titheMutationInputs); + + for (TitheMutationInput titheMutationInput : titheMutationInputs) { +// New Builder object for each tithe + TitheBuilder titheBuilder = new TitheBuilder(); + TitheEntity tithe = titheBuilder.titheAmount(titheMutationInput.getTitheAmount()) + .person(person) + .family(person.getFamily()) + .koottayma(person.getFamily().getKoottayma()) + .parish(person.getFamily().getKoottayma().getParish()) + .forane(person.getFamily().getKoottayma().getParish().getForane()) + .timeStamp(titheMutationInput.getTimeStamp()) + .build(); + tithes.add(tithe); + } + } + return tithes; + } + +} diff --git a/Tithe-Spring/src/main/java/com/tithe/model/FamilyMutationInput.java b/Tithe-Spring/src/main/java/com/tithe/model/FamilyMutationInput.java index 9f43f55..5bd7243 100755 --- a/Tithe-Spring/src/main/java/com/tithe/model/FamilyMutationInput.java +++ b/Tithe-Spring/src/main/java/com/tithe/model/FamilyMutationInput.java @@ -3,6 +3,8 @@ */ package com.tithe.model; +import java.util.List; + import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Positive; @@ -26,6 +28,11 @@ public class FamilyMutationInput { @Positive(message = "Id of Koottayma should be valid") @NotNull(message = "Id of Koottayma should not be empty or null") Long koottaymaId; + + @NotNull(message = "Head of Family should not be empty or null") + PersonMutationInput headOfFamily; + + List persons; Boolean active = true; diff --git a/Tithe-Spring/src/main/java/com/tithe/model/PersonMutationInput.java b/Tithe-Spring/src/main/java/com/tithe/model/PersonMutationInput.java index fa600de..b2b83b2 100755 --- a/Tithe-Spring/src/main/java/com/tithe/model/PersonMutationInput.java +++ b/Tithe-Spring/src/main/java/com/tithe/model/PersonMutationInput.java @@ -27,8 +27,8 @@ public class PersonMutationInput { @NotBlank(message = "Name of Person should not be empty or null") String personName; - @Positive(message = "Id of Family should be valid") - @NotNull(message = "Id of Family should not be empty or null") +// @Positive(message = "Id of Family should be valid") +// @NotNull(message = "Id of Family should not be empty or null") Long familyId; @Positive(message = "Id of Relation should be valid") diff --git a/Tithe-Spring/src/main/java/com/tithe/service/mutation/FamilyMutationService.java b/Tithe-Spring/src/main/java/com/tithe/service/mutation/FamilyMutationService.java index 61304e7..9679120 100755 --- a/Tithe-Spring/src/main/java/com/tithe/service/mutation/FamilyMutationService.java +++ b/Tithe-Spring/src/main/java/com/tithe/service/mutation/FamilyMutationService.java @@ -3,6 +3,8 @@ */ package com.tithe.service.mutation; + +import java.util.List; import java.util.Optional; import org.springframework.beans.factory.annotation.Autowired; @@ -10,9 +12,10 @@ import com.tithe.entity.AddressEntity; import com.tithe.entity.FamilyEntity; -import com.tithe.entity.KoottaymaEntity; +import com.tithe.entity.PersonEntity; import com.tithe.model.AddressMutationInput; import com.tithe.model.FamilyMutationInput; +import com.tithe.model.PersonMutationInput; import com.tithe.repository.FamilyRepository; import com.tithe.service.query.AddressQueryService; import com.tithe.service.query.KoottaymaQueryService; @@ -20,6 +23,7 @@ import graphql.GraphQLException; + /** * @author Ashish Sam T George * @@ -36,6 +40,9 @@ public class FamilyMutationService { @Autowired private KoottaymaQueryService koottaymaQueryService; + @Autowired + private PersonMutationService personMutationService; + @Autowired private FamilyRepository familyRepository; @@ -46,19 +53,37 @@ public FamilyEntity createOneFamily(FamilyMutationInput familyMutationInput) { FamilyEntity family = new FamilyEntity(); family.setFamilyName(familyMutationInput.getFamilyName()); +// If the same address already exists, then set that address to family entity or else build a new address +// entity and set it to family entity AddressMutationInput addressInput = familyMutationInput.getAddress(); - if (addressInput!=null) { + if (addressInput != null) { AddressEntity address = addressQueryService.getOneAddress(addressInput); - if (address!=null) { + if (address != null) { family.setAddress(address); - } - else { + } else { family.setAddress(addressQueryService.buildAddressEntity(addressInput)); } } family.setPhone(familyMutationInput.getPhone()); - family.setKoottayma(koottaymaQueryService.getOneKoottayma(familyMutationInput.getKoottaymaId())); + family.setKoottayma( + koottaymaQueryService.getOneKoottayma(familyMutationInput.getKoottaymaId())); + +// Build Head of Family person entity + PersonMutationInput headOfFamilyInput = familyMutationInput.getHeadOfFamily(); + PersonEntity headOfFamily = personMutationService.buildPersonWithTithe(family, + headOfFamilyInput); + family.setHeadOfFamily(headOfFamily); + +// Build Family members + List familyMemberInputs = familyMutationInput.getPersons(); + if (familyMemberInputs != null) { + + objectValidation.validateObjects(familyMemberInputs); + List familyMembers = personMutationService.buildPersonsWithTithe(family, + familyMemberInputs); + family.setPersons(familyMembers); + } family.setActive(familyMutationInput.getActive()); @@ -66,24 +91,24 @@ public FamilyEntity createOneFamily(FamilyMutationInput familyMutationInput) { } public FamilyEntity activateOneFamily(Long familyId) { - if (familyId!=null) { + if (familyId != null) { Optional obtainedFamily = familyRepository.findById(familyId); FamilyEntity family = obtainedFamily.orElseThrow(); family.setActive(true); return familyRepository.save(family); } - GraphQLException exception = new GraphQLException("Some Error Occured") ; + GraphQLException exception = new GraphQLException("Some Error Occured"); throw exception; } public FamilyEntity deactivateOneFamily(Long familyId) { - if (familyId!=null) { + if (familyId != null) { Optional obtainedFamily = familyRepository.findById(familyId); FamilyEntity family = obtainedFamily.orElseThrow(); family.setActive(false); return familyRepository.save(family); } - GraphQLException exception = new GraphQLException("Some Error Occured") ; + GraphQLException exception = new GraphQLException("Some Error Occured"); throw exception; } diff --git a/Tithe-Spring/src/main/java/com/tithe/service/mutation/PersonMutationService.java b/Tithe-Spring/src/main/java/com/tithe/service/mutation/PersonMutationService.java index 1bdc6dd..2e70183 100755 --- a/Tithe-Spring/src/main/java/com/tithe/service/mutation/PersonMutationService.java +++ b/Tithe-Spring/src/main/java/com/tithe/service/mutation/PersonMutationService.java @@ -3,14 +3,22 @@ */ package com.tithe.service.mutation; + import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.Optional; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import com.tithe.entity.EducationEntity; +import com.tithe.entity.FamilyEntity; +import com.tithe.entity.OccupationEntity; +import com.tithe.entity.PersonBuilder; import com.tithe.entity.PersonEntity; +import com.tithe.entity.RelationEntity; +import com.tithe.entity.TitheBuilder; import com.tithe.entity.TitheEntity; import com.tithe.model.PersonMutationInput; import com.tithe.model.TitheMutationInput; @@ -18,10 +26,14 @@ import com.tithe.service.query.EducationQueryService; import com.tithe.service.query.FamilyQueryService; import com.tithe.service.query.OccupationQueryService; +import com.tithe.service.query.PersonQueryService; import com.tithe.service.query.RelationQueryService; import com.tithe.service.query.TitheQueryService; import com.tithe.utils.ObjectValidation; +import graphql.GraphQLException; + + /** * @author Ashish Sam T George * @@ -35,6 +47,9 @@ public class PersonMutationService { @Autowired private PersonRepository personRepository; + @Autowired + private PersonQueryService personQueryService; + @Autowired private FamilyQueryService familyQueryService; @@ -52,34 +67,16 @@ public class PersonMutationService { public PersonEntity createOnePerson(PersonMutationInput personMutationInput) { +// Validate the obtained input objectValidation.validateObject(personMutationInput); - PersonEntity person = new PersonEntity(); - person.setBaptismName(personMutationInput.getBaptismName()); - person.setPersonName(personMutationInput.getPersonName()); - person.setFamily(familyQueryService.getOneFamily(personMutationInput.getFamilyId())); - person.setRelation(relationQueryService.getOneRelation(personMutationInput.getRelationId())); - person.setGender(personMutationInput.getGender()); - person.setDob(personMutationInput.getDob()); - person.setPhone(personMutationInput.getPhone()); - - List titheInputs = personMutationInput.getTithes(); - List tithes = new ArrayList<>(); - if (titheInputs!=null && titheInputs.size()!=0) { - tithes = titheQueryService.buildTitheEntities(person, titheInputs); - } - person.setTithes(tithes); - - person.setMoved(personMutationInput.getMoved()); - - if (personMutationInput.getEducationIds().size()!=0) { - person.setEducations(educationQueryService.getManyEducations(personMutationInput.getEducationIds())); - } - if (personMutationInput.getOccupationIds().size()!=0) { - person.setOccupations(occupationQueryService.getManyOccupations(personMutationInput.getOccupationIds())); +// Get family using the id, if exists, or else return error + FamilyEntity family = familyQueryService.getOneFamily(personMutationInput.getFamilyId()); + if (family == null) { + throw new GraphQLException("Family does not exist"); } - person.setActive(personMutationInput.getActive()); + PersonEntity person = buildPersonWithTithe(family, personMutationInput); return personRepository.save(person); } @@ -95,7 +92,7 @@ public PersonEntity activateOnePerson(Long id) { public List activateManyPersons(List ids) { List persons = personRepository.findAllById(ids); - if (persons.size()!=0) { + if (persons.size() != 0) { for (PersonEntity person : persons) { person.setActive(true); } @@ -116,7 +113,7 @@ public PersonEntity deactivateOnePerson(Long id) { public List deactivateManyPersons(List ids) { List persons = personRepository.findAllById(ids); - if (persons.size()!=0) { + if (persons.size() != 0) { for (PersonEntity person : persons) { person.setActive(false); } @@ -124,5 +121,62 @@ public List deactivateManyPersons(List ids) { } return null; } + + public List getEducations(List educationIds) { + List educations = new ArrayList<>(); + if (educationIds != null && educationIds.size() != 0) { + educations = educationQueryService.getManyEducations(educationIds); + } + return educations; + } + + public List getOccupations(List occupationIds){ + List occupations = new ArrayList<>(); + if (occupationIds != null && occupationIds.size() != 0) { + occupations = occupationQueryService.getManyOccupations(occupationIds); + } + return occupations; + } + + public PersonEntity buildPersonWithTithe(FamilyEntity family, PersonMutationInput personMutationInput) { + objectValidation.validateObject(personMutationInput); + + RelationEntity relation = relationQueryService + .getOneRelation(personMutationInput.getRelationId()); + + List educations = getEducations(personMutationInput.getEducationIds()); + + List occupations = getOccupations(personMutationInput.getOccupationIds()); + + PersonBuilder personBuilder = new PersonBuilder(); + PersonEntity person = personBuilder.baptismName(personMutationInput.getBaptismName()) + .personName(personMutationInput.getPersonName()) + .family(family) + .relation(relation) + .gender(personMutationInput.getGender()) + .dob(personMutationInput.getDob()) + .phone(personMutationInput.getPhone()) + .moved(personMutationInput.getMoved()) + .educations(educations) + .occupations(occupations) + .active(personMutationInput.getActive()) + .build(); + +// Build Tithe entity + TitheBuilder titheBuilder = new TitheBuilder(); + List tithes = titheBuilder.buildTithe(person, personMutationInput.getTithes()); + person.setTithes(tithes); + + return person; + } + + public List buildPersonsWithTithe(FamilyEntity family, List personMutationInputs){ + List persons = new ArrayList<>(); + for(PersonMutationInput personMutationInput: personMutationInputs) { + PersonEntity person = buildPersonWithTithe(family, personMutationInput); + persons.add(person); + } + return persons; + } } diff --git a/Tithe-Spring/src/main/java/com/tithe/service/mutation/TitheMutationService.java b/Tithe-Spring/src/main/java/com/tithe/service/mutation/TitheMutationService.java index edb15bf..f8fce65 100755 --- a/Tithe-Spring/src/main/java/com/tithe/service/mutation/TitheMutationService.java +++ b/Tithe-Spring/src/main/java/com/tithe/service/mutation/TitheMutationService.java @@ -9,6 +9,7 @@ import org.springframework.stereotype.Service; import com.tithe.entity.PersonEntity; +import com.tithe.entity.TitheBuilder; import com.tithe.entity.TitheEntity; import com.tithe.model.TitheMutationInput; import com.tithe.repository.TitheRepository; @@ -36,7 +37,8 @@ public List createManyTithes(Long personId, // TODO Try adding @NotNull in the method parameter above - No Use PersonEntity person = personQueryService.getOnePerson(personId); - List tithes = titheQueryService.buildTitheEntities(person, titheMutationInputs); + TitheBuilder titheBuilder = new TitheBuilder(); + List tithes = titheBuilder.buildTithe(person, titheMutationInputs); return titheRepository.saveAll(tithes); } diff --git a/Tithe-Spring/src/main/java/com/tithe/service/query/PersonQueryService.java b/Tithe-Spring/src/main/java/com/tithe/service/query/PersonQueryService.java index 148d9ec..0bc00de 100755 --- a/Tithe-Spring/src/main/java/com/tithe/service/query/PersonQueryService.java +++ b/Tithe-Spring/src/main/java/com/tithe/service/query/PersonQueryService.java @@ -39,6 +39,7 @@ public class PersonQueryService { @Autowired private FamilyQueryService familyQueryService; + public PersonEntity getOnePerson(Long id) { Optional person = personRepository.findById(id); diff --git a/Tithe-Spring/src/main/java/com/tithe/service/query/TitheQueryService.java b/Tithe-Spring/src/main/java/com/tithe/service/query/TitheQueryService.java index 9e94995..5fd23c2 100755 --- a/Tithe-Spring/src/main/java/com/tithe/service/query/TitheQueryService.java +++ b/Tithe-Spring/src/main/java/com/tithe/service/query/TitheQueryService.java @@ -3,17 +3,8 @@ */ package com.tithe.service.query; -import java.util.ArrayList; -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import com.tithe.entity.PersonEntity; -import com.tithe.entity.TitheEntity; -import com.tithe.model.TitheMutationInput; -import com.tithe.utils.ObjectValidation; - /** * @author Ashish Sam T George * @@ -21,30 +12,4 @@ @Service public class TitheQueryService { - @Autowired - private ObjectValidation objectValidation; - - public List buildTitheEntities(PersonEntity person, - List titheMutationInputs) { - - objectValidation.validateObjects(titheMutationInputs); - - List tithes = new ArrayList<>(); - for (TitheMutationInput titheInput : titheMutationInputs) { - TitheEntity tithe = new TitheEntity(); - tithe.setTitheAmount(titheInput.getTitheAmount()); - tithe.setTimeStamp(titheInput.getTimeStamp()); - tithe.setPerson(person); - tithe.setFamily(person.getFamily()); - tithe.setKoottayma(tithe.getFamily().getKoottayma()); - tithe.setParish(tithe.getKoottayma().getParish()); - tithe.setForane(tithe.getParish().getForane()); - - tithes.add(tithe); - } - - return tithes; - - } - } diff --git a/Tithe-Spring/src/main/resources/graphql/types/Family.graphqls b/Tithe-Spring/src/main/resources/graphql/types/Family.graphqls index fc06189..57a32ec 100755 --- a/Tithe-Spring/src/main/resources/graphql/types/Family.graphqls +++ b/Tithe-Spring/src/main/resources/graphql/types/Family.graphqls @@ -4,6 +4,7 @@ type Family{ address: Address phone: String koottayma: Koottayma! + headOfFamily: Person persons: [Person] tithes: [Tithe] active: Boolean @@ -21,5 +22,7 @@ input FamilyMutationInput{ address: AddressMutationInput phone: String koottaymaId: ID! + headOfFamily: PersonMutationThroughFamilyInput! + persons: [PersonMutationThroughFamilyInput] active: Boolean = true } diff --git a/Tithe-Spring/src/main/resources/graphql/types/Person.graphqls b/Tithe-Spring/src/main/resources/graphql/types/Person.graphqls index 8e731ed..bd2c1b1 100755 --- a/Tithe-Spring/src/main/resources/graphql/types/Person.graphqls +++ b/Tithe-Spring/src/main/resources/graphql/types/Person.graphqls @@ -38,6 +38,20 @@ input PersonMutationInput{ active: Boolean = true } +input PersonMutationThroughFamilyInput{ + baptismName: String! + personName: String! + relationId: ID! + gender: GenderEnum! + dob: LocalDate! + phone: String + tithes: [TitheMutationInput] + moved: Boolean = false + educationIds: [ID] + occupationIds: [ID] + active: Boolean = true +} + type Relation{ relationId: ID! relationName: String! From 95675868f81e6184a1c2c7e5e6ea20673e92be85 Mon Sep 17 00:00:00 2001 From: Ashish Sam Date: Fri, 29 Sep 2023 16:55:34 +0530 Subject: [PATCH 3/8] Create Head of family and family members along when creating family - Clear the input fields once creation is successful --- Tithe-Vue/src/components/AddressForm.vue | 27 ++++++-- .../Forms/AddPersonInFamilyForm.vue | 29 ++++---- Tithe-Vue/src/components/Forms/PersonForm.vue | 66 +++++++++++-------- .../FamilyByParishSingleSelectBox.vue | 11 +++- .../SearchBoxes/ForaneSingleSelectBox.vue | 11 +++- .../KoottaymaByParishSingleSelectBox.vue | 11 +++- .../ParishByForaneSingleSelectBox.vue | 11 +++- .../SearchBoxes/RelationSingleSelectBox.vue | 9 +++ .../SearchBoxes/SingleSelectBox.vue | 11 +++- Tithe-Vue/src/views/FamilyView.vue | 54 +++++++++++++-- 10 files changed, 184 insertions(+), 56 deletions(-) diff --git a/Tithe-Vue/src/components/AddressForm.vue b/Tithe-Vue/src/components/AddressForm.vue index 17cf0bc..5612b7a 100644 --- a/Tithe-Vue/src/components/AddressForm.vue +++ b/Tithe-Vue/src/components/AddressForm.vue @@ -102,7 +102,7 @@ const changeInStreet = (entity) => { }; watch(street, (value) => { - address.streetId = value.id; + address.streetId = value?.id ?? ""; emit("addressFormChange", address); }); @@ -200,7 +200,7 @@ const changeInCity = (entity) => { }; watch(city, (value) => { - address.cityId = value.id; + address.cityId = value?.id ?? ""; emit("addressFormChange", address); }); @@ -281,7 +281,7 @@ const changeInDistrict = (entity) => { }; watch(district, (value) => { - address.districtId = value.id; + address.districtId = value?.id ?? ""; emit("addressFormChange", address); }); @@ -362,7 +362,7 @@ const changeInState = (entity) => { }; watch(state, (value) => { - address.stateId = value.id; + address.stateId = value?.id ?? ""; emit("addressFormChange", address); }); @@ -443,7 +443,7 @@ const changeInPincode = (entity) => { }; watch(pincode, (value) => { - address.pincodeId = value.id; + address.pincodeId = value?.id ?? ""; emit("addressFormChange", address); }); @@ -472,12 +472,24 @@ const createPincodeOption = (option, setSelected) => { }); }; +const addressRef = ref(null); +const cityRef = ref(null); +const districtRef = ref(null); +const stateRef = ref(null); +const pincodeRef = ref(null); + const clearAddressFields = () => { street.value = ""; city.value = ""; district.value = ""; state.value = ""; pincode.value = ""; + + addressRef.value.clearField(); + cityRef.value.clearField(); + districtRef.value.clearField(); + stateRef.value.clearField(); + pincodeRef.value.clearField(); }; defineExpose({ @@ -500,6 +512,7 @@ defineExpose({ -import { ref } from "vue"; +import { ref, watch } from "vue"; import { mdiClose, mdiPlus } from "@mdi/js"; import FormField from "@/components/FormField.vue"; -import FormControl from "@/components/FormControl.vue"; import BaseButton from "@/components/BaseButton.vue"; import PersonForm from "@/components/Forms/PersonForm.vue"; +const emits = defineEmits(["changeInFamilyMembers"]); + const persons = ref([]); const addInput = () => { @@ -17,13 +18,25 @@ const addInput = () => { const removeInput = (counter) => { persons.value.splice(counter, 1); }; + +watch(persons.value, () => { + emits("changeInFamilyMembers", persons.value); +}); + +const clearFamilyMembersForm = () => { + persons.value.splice(0, persons.value.length); +}; +defineExpose({ + clearFamilyMembersForm, +});