Skip to content

Commit

Permalink
Merge pull request #71 from TC4Y-777/dev
Browse files Browse the repository at this point in the history
Change Head of Family in Family Page
  • Loading branch information
getwithashish authored Oct 4, 2023
2 parents 8371920 + 2cef999 commit edbb08a
Show file tree
Hide file tree
Showing 41 changed files with 2,008 additions and 327 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
*/
package com.tithe.controller.mutation;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.graphql.data.method.annotation.Argument;
import org.springframework.graphql.data.method.annotation.MutationMapping;
Expand All @@ -11,8 +14,10 @@
import com.tithe.entity.FamilyEntity;
import com.tithe.entity.KoottaymaEntity;
import com.tithe.model.FamilyMutationInput;
import com.tithe.model.PersonRelationInputModel;
import com.tithe.service.mutation.FamilyMutationService;


/**
* @author Ashish Sam T George
*
Expand All @@ -24,15 +29,23 @@ public class FamilyMutations {
private FamilyMutationService familyMutationService;

@MutationMapping(name = "createOneFamily")
public FamilyEntity createOneFamily(@Argument(name = "family") FamilyMutationInput familyMutationInput) {
public FamilyEntity createOneFamily(
@Argument(name = "family") FamilyMutationInput familyMutationInput) {
return familyMutationService.createOneFamily(familyMutationInput);
}


@MutationMapping(name = "changeHeadOfFamily")
public FamilyEntity changeHeadOfFamily(@Argument(name = "familyId") Long familyId,
@Argument(name = "newHeadOfFamily") PersonRelationInputModel headOfFamily,
@Argument(name = "persons") List<PersonRelationInputModel> persons) {
return familyMutationService.changeHeadOfFamily(familyId, headOfFamily, persons);
}

@MutationMapping(name = "activateOneFamily")
public FamilyEntity activateOneFamily(@Argument(name = "familyId") Long familyId) {
return familyMutationService.activateOneFamily(familyId);
}

@MutationMapping(name = "deactivateOneFamily")
public FamilyEntity deactivateOneFamily(@Argument(name = "familyId") Long familyId) {
return familyMutationService.deactivateOneFamily(familyId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
package com.tithe.controller.mutation;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -23,6 +24,7 @@
import com.tithe.service.mutation.RelationMutationService;
import com.tithe.service.mutation.TitheMutationService;


/**
* @author Ashish Sam T George
*
Expand All @@ -46,10 +48,23 @@ public class PersonMutations {
private TitheMutationService titheMutationService;

@MutationMapping(name = "createOnePerson")
public PersonEntity createOnePerson(@Argument(name = "person") PersonMutationInput personMutationInput) {
public PersonEntity createOnePerson(
@Argument(name = "person") PersonMutationInput personMutationInput) {
return personMutationService.createOnePerson(personMutationInput);
}

@MutationMapping(name = "createManyPersonsInOneFamily")
public List<PersonEntity> createManyPersons(@Argument(name = "familyId") Long familyId,
@Argument(name = "persons") List<PersonMutationInput> personMutationInputs) {
return personMutationService.createManyPersonsInOneFamily(familyId, personMutationInputs);
}

@MutationMapping(name = "changeRelation")
public PersonEntity changeRelation(@Argument(name = "personId") Long personId,
@Argument(name = "relationId") Long relationId) {
return personMutationService.changeRelation(personId, relationId);
}

@MutationMapping(name = "activateOnePerson")
public PersonEntity activateOnePerson(@Argument Long id) {
return personMutationService.activateOnePerson(id);
Expand All @@ -73,24 +88,29 @@ public List<PersonEntity> deactivateManyPersons(@Argument List<Long> ids) {
@MutationMapping(name = "createOneEducation")
public EducationEntity createOneEducation(@Argument(name = "education") String educationName) {
List<String> educationNames = List.of(educationName);
List<EducationEntity> educations = educationMutationService.createManyEducations(educationNames);
List<EducationEntity> educations = educationMutationService
.createManyEducations(educationNames);
return educations.get(0);
}

@MutationMapping(name = "createManyEducations")
public List<EducationEntity> createManyEducations(@Argument(name = "educations") List<String> educationNames) {
public List<EducationEntity> createManyEducations(
@Argument(name = "educations") List<String> educationNames) {
return educationMutationService.createManyEducations(educationNames);
}

@MutationMapping(name = "createOneOccupation")
public OccupationEntity createOneOccupation(@Argument(name = "occupation") String occupationName) {
public OccupationEntity createOneOccupation(
@Argument(name = "occupation") String occupationName) {
List<String> occupationNames = List.of(occupationName);
List<OccupationEntity> occupations = occupationMutationService.createManyOccupations(occupationNames);
List<OccupationEntity> occupations = occupationMutationService
.createManyOccupations(occupationNames);
return occupations.get(0);
}

@MutationMapping(name = "createManyOccupations")
public List<OccupationEntity> createManyOccupations(@Argument(name = "occupations") List<String> occupationNames) {
public List<OccupationEntity> createManyOccupations(
@Argument(name = "occupations") List<String> occupationNames) {
return occupationMutationService.createManyOccupations(occupationNames);
}

Expand All @@ -102,15 +122,17 @@ public RelationEntity createOneRelation(@Argument(name = "relation") String rela
}

@MutationMapping(name = "createManyRelations")
public List<RelationEntity> createManyRelations(@Argument(name = "relations") List<String> relationNames) {
public List<RelationEntity> createManyRelations(
@Argument(name = "relations") List<String> relationNames) {
return relationMutationService.createManyRelations(relationNames);
}

@MutationMapping(name = "createOneTithe")
public TitheEntity createOneTithe(@Argument(name = "personId") Long personId,
@Argument(name = "tithe") TitheMutationInput titheMutationInput) {
List<TitheMutationInput> titheMutationInputs = List.of(titheMutationInput);
List<TitheEntity> tithes = titheMutationService.createManyTithes(personId, titheMutationInputs);
List<TitheEntity> tithes = titheMutationService.createManyTithes(personId,
titheMutationInputs);
return tithes.get(0);
}

Expand Down
13 changes: 11 additions & 2 deletions Tithe-Spring/src/main/java/com/tithe/entity/FamilyEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
package com.tithe.entity;


import java.util.List;

import jakarta.persistence.CascadeType;
Expand All @@ -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;
Expand All @@ -21,6 +23,7 @@
import lombok.Data;
import lombok.NoArgsConstructor;


/**
* @author Ashish Sam T George
*
Expand All @@ -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
Expand All @@ -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<PersonEntity> persons;

@OneToMany(mappedBy = "family")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import java.util.List;

import com.tithe.model.OccupationSectorEnum;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
Expand All @@ -13,6 +15,7 @@
import jakarta.persistence.ManyToMany;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand Down
114 changes: 114 additions & 0 deletions Tithe-Spring/src/main/java/com/tithe/entity/PersonBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/**
*
*/
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.model.OccupationSectorEnum;
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<TitheEntity> tithes;
private Boolean moved = false;
private List<EducationEntity> educations;
private OccupationSectorEnum occupationSector;
private List<OccupationEntity> 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<TitheEntity> tithes) {
// this.tithes = tithes;
// return this;
// }

public PersonBuilder moved(Boolean moved) {
this.moved = moved;
return this;
}

public PersonBuilder educations(List<EducationEntity> educations) {
this.educations = educations;
return this;
}

public PersonBuilder occupationSector(OccupationSectorEnum occupationSector) {
this.occupationSector = occupationSector;
return this;
}

public PersonBuilder occupations(List<OccupationEntity> 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, occupationSector, occupations, active);
return person;
}

}
8 changes: 6 additions & 2 deletions Tithe-Spring/src/main/java/com/tithe/entity/PersonEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.List;

import com.tithe.model.GenderEnum;
import com.tithe.model.OccupationSectorEnum;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
Expand Down Expand Up @@ -53,8 +54,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;

Expand Down Expand Up @@ -84,6 +86,8 @@ public class PersonEntity {
@JoinTable(name = "person_educations_table", uniqueConstraints =
@UniqueConstraint(columnNames = {"persons_person_id", "educations_education_id"}))
private List<EducationEntity> educations;

private OccupationSectorEnum occupationSector;

@ManyToMany(cascade = CascadeType.PERSIST)
@JoinTable(name = "person_occupations_table", joinColumns = @JoinColumn(name = "person_id"),
Expand Down
Loading

0 comments on commit edbb08a

Please sign in to comment.