diff --git a/pom.xml b/pom.xml index 34451f1..84e29a0 100755 --- a/pom.xml +++ b/pom.xml @@ -34,6 +34,11 @@ mysql-connector-java + + org.springframework.boot + spring-boot-starter-data-mongodb + + org.springframework.boot spring-boot-starter-test diff --git a/src/main/java/com/coddicted/school/student/constants/SwaggerConstant.java b/src/main/java/com/coddicted/school/student/constants/SwaggerConstant.java index e2202bc..1561a9e 100644 --- a/src/main/java/com/coddicted/school/student/constants/SwaggerConstant.java +++ b/src/main/java/com/coddicted/school/student/constants/SwaggerConstant.java @@ -8,12 +8,15 @@ public interface SwaggerConstant String AUTO_GENERATED_STUDENT_ID = "Auto-generated student ID"; String STUDENT_FIRST_NAME = "Student first name"; + String STUDENT_MIDDLE_NAME = "Student middle name"; String STUDENT_LAST_NAME = "Student last name"; + String STUDENT_GENDER = "Student's Gender"; String STUDENT_REGISTRATION_NUMBER = "Student register number"; String STUDENT_RELIGION = "Student's religion"; String STUDENT_CASTE = "Student's caste"; + String STUDENT_CATEGORY = "Student's category"; String STUDENT_FATHER_NAME = "Student's father's name"; String STUDENT_MOTHER_NAME = "Student's mother's name"; @@ -22,6 +25,10 @@ public interface SwaggerConstant String STUDENT_AADHAR_NUMBER = "Student's Aadhar (UIDAI) number"; String STUDENT_DATE_OF_BIRTH = "Student's date of birth"; + String STUDENT_ADDRESS_LIST = "Student's Address List"; + String STUDENT_EMAIL_LIST = "Student's Email List"; + String STUDENT_PHONE_LIST = "Student's Phone List"; + String STUDENT_DATE_OF_ADMISSION = "Student's date of admission at school"; } diff --git a/src/main/java/com/coddicted/school/student/model/Address.java b/src/main/java/com/coddicted/school/student/model/Address.java new file mode 100644 index 0000000..d2d9c9a --- /dev/null +++ b/src/main/java/com/coddicted/school/student/model/Address.java @@ -0,0 +1,17 @@ +package com.coddicted.school.student.model; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class Address +{ + private AddressType type; + private String address1; + private String address2; + private String city; + private String state; + private String country; + private String zip; +} diff --git a/src/main/java/com/coddicted/school/student/model/AddressType.java b/src/main/java/com/coddicted/school/student/model/AddressType.java new file mode 100644 index 0000000..d36931f --- /dev/null +++ b/src/main/java/com/coddicted/school/student/model/AddressType.java @@ -0,0 +1,21 @@ +package com.coddicted.school.student.model; + +public enum AddressType +{ + HOME("Home"), + BUSINESS("Business"), + MAILING("Mailing"), + SCHOOL("School"); + + private String name; + + AddressType(String name) + { + this.name = name; + } + + public String toString() + { + return this.name; + } +} diff --git a/src/main/java/com/coddicted/school/student/model/Email.java b/src/main/java/com/coddicted/school/student/model/Email.java new file mode 100644 index 0000000..597684f --- /dev/null +++ b/src/main/java/com/coddicted/school/student/model/Email.java @@ -0,0 +1,12 @@ +package com.coddicted.school.student.model; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class Email +{ + private EmailType type; + private String value; +} diff --git a/src/main/java/com/coddicted/school/student/model/EmailType.java b/src/main/java/com/coddicted/school/student/model/EmailType.java new file mode 100644 index 0000000..3c9fc1d --- /dev/null +++ b/src/main/java/com/coddicted/school/student/model/EmailType.java @@ -0,0 +1,22 @@ +package com.coddicted.school.student.model; + +public enum EmailType +{ + HOME("Home"), + WORK("Work"), + SCHOOL("School"), + OTHER("Other"), + CUSTOM("Custom"); + + private String name; + + EmailType(String name) + { + this.name = name; + } + + public String toString() + { + return this.name; + } +} diff --git a/src/main/java/com/coddicted/school/student/model/Gender.java b/src/main/java/com/coddicted/school/student/model/Gender.java new file mode 100644 index 0000000..d165611 --- /dev/null +++ b/src/main/java/com/coddicted/school/student/model/Gender.java @@ -0,0 +1,21 @@ +package com.coddicted.school.student.model; + +public enum Gender +{ + MALE("Male"), + FEMALE("Female"), + OTHER("Other"); + + private String name; + + Gender(String name) + { + this.name = name; + } + + @Override + public String toString() + { + return this.name; + } +} diff --git a/src/main/java/com/coddicted/school/student/model/Person.java b/src/main/java/com/coddicted/school/student/model/Person.java new file mode 100644 index 0000000..c4dd652 --- /dev/null +++ b/src/main/java/com/coddicted/school/student/model/Person.java @@ -0,0 +1,34 @@ +package com.coddicted.school.student.model; + +import java.time.LocalDate; +import java.util.List; + +public interface Person +{ + String getAadharNumber(); + void setAadharNumber(String aadharNumber); + + Gender getGender(); + void setGender(Gender gender); + + String getFirstName(); + void setFirstName(String firstName); + + String getMiddleName(); + void setMiddleName(String middleName); + + String getLastName(); + void setLastName(String lastName); + + LocalDate getDateOfBirth(); + void setDateOfBirth(LocalDate dateOfBirth); + + List getEmailList(); + void setEmailList(List emailList); + + List getPhoneList(); + void setPhoneList(List phoneList); + + List
getAddressList(); + void setAddressList(List
addressList); +} diff --git a/src/main/java/com/coddicted/school/student/model/Phone.java b/src/main/java/com/coddicted/school/student/model/Phone.java new file mode 100644 index 0000000..3ee9a79 --- /dev/null +++ b/src/main/java/com/coddicted/school/student/model/Phone.java @@ -0,0 +1,12 @@ +package com.coddicted.school.student.model; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class Phone +{ + private PhoneType type; + private String value; +} diff --git a/src/main/java/com/coddicted/school/student/model/PhoneType.java b/src/main/java/com/coddicted/school/student/model/PhoneType.java new file mode 100644 index 0000000..9bc2b3d --- /dev/null +++ b/src/main/java/com/coddicted/school/student/model/PhoneType.java @@ -0,0 +1,27 @@ +package com.coddicted.school.student.model; + +public enum PhoneType +{ + HOME("Home"), + WORK("Work"), + MAIN("Main"), + WORK_FAX("Work Fax"), + HOME_FAX("Home Fax"), + PAGER("Pager"), + OTHER("Other"), + CUSTOM("Custom"), + MOBILE("Mobile"); + + + private String name; + + PhoneType(String name) + { + this.name = name; + } + + public String toString() + { + return this.name; + } +} diff --git a/src/main/java/com/coddicted/school/student/model/Student.java b/src/main/java/com/coddicted/school/student/model/Student.java index fa7d05d..4e92c4b 100755 --- a/src/main/java/com/coddicted/school/student/model/Student.java +++ b/src/main/java/com/coddicted/school/student/model/Student.java @@ -9,25 +9,44 @@ import io.swagger.annotations.ApiModelProperty; import io.swagger.models.Swagger; import lombok.Data; +import lombok.Getter; +import lombok.Setter; import java.time.LocalDate; +import java.util.List; @Entity // This tells Hibernate to make a table out of this class @Data -public class Student { - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - @ApiModelProperty(notes = SwaggerConstant.AUTO_GENERATED_STUDENT_ID) - private Integer id; +@Getter +@Setter +public class Student implements Person +{ + @ApiModelProperty(notes = SwaggerConstant.STUDENT_AADHAR_NUMBER) + private String aadharNumber; @ApiModelProperty(notes = SwaggerConstant.STUDENT_FIRST_NAME) private String firstName; + @ApiModelProperty(notes = SwaggerConstant.STUDENT_MIDDLE_NAME) + private String middleName; + @ApiModelProperty(notes = SwaggerConstant.STUDENT_LAST_NAME) private String lastName; - @ApiModelProperty(notes = SwaggerConstant.STUDENT_REGISTRATION_NUMBER) - private String studentRegistrationNumber; + @ApiModelProperty(notes = SwaggerConstant.STUDENT_GENDER) + private Gender gender; + + @ApiModelProperty(notes = SwaggerConstant.STUDENT_DATE_OF_BIRTH) + private LocalDate dateOfBirth; + + @ApiModelProperty(notes = SwaggerConstant.STUDENT_PHONE_LIST) + private List phoneList; + + @ApiModelProperty(notes = SwaggerConstant.STUDENT_EMAIL_LIST) + private List emailList; + + @ApiModelProperty(notes = SwaggerConstant.STUDENT_ADDRESS_LIST) + private List
addressList; @ApiModelProperty(notes = SwaggerConstant.STUDENT_RELIGION) private String religion; @@ -39,23 +58,12 @@ public class Student { private String category; @ApiModelProperty(notes = SwaggerConstant.STUDENT_FATHER_NAME) - private String fatherName; + private Person father; @ApiModelProperty(notes = SwaggerConstant.STUDENT_MOTHER_NAME) - private String motherName; + private Person mother; @ApiModelProperty(notes = SwaggerConstant.STUDENT_GUARDIAN_NAME) - private String guardianName; - - @ApiModelProperty(notes = SwaggerConstant.STUDENT_AADHAR_NUMBER) - private String aadharNumber; - // Various date fields - // TODO Need to check the data type for them - @ApiModelProperty(notes = SwaggerConstant.STUDENT_DATE_OF_BIRTH) - private LocalDate dateOfBirth; + private Person guardianName; - // TODO Need to check placement of below field. Should it be placed in some other class? - // this is because the date would change on class promotion/ school change. - @ApiModelProperty(notes = SwaggerConstant.STUDENT_DATE_OF_ADMISSION) - private LocalDate dateOfAdmission; } diff --git a/src/main/java/com/coddicted/school/student/repository/StudentRepository.java b/src/main/java/com/coddicted/school/student/repository/StudentRepository.java index 9a5dedd..bfc6737 100755 --- a/src/main/java/com/coddicted/school/student/repository/StudentRepository.java +++ b/src/main/java/com/coddicted/school/student/repository/StudentRepository.java @@ -1,14 +1,23 @@ package com.coddicted.school.student.repository; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.repository.CrudRepository; - import com.coddicted.school.student.model.Student; +import org.springframework.data.mongodb.repository.MongoRepository; -// This will be AUTO IMPLEMENTED by Spring into a Bean called StudentRepository -// CRUD refers Create, Read, Update, Delete +import java.time.LocalDate; +import java.util.List; -public interface StudentRepository extends JpaRepository +public interface StudentRepository extends MongoRepository { + List findAll(); + List findAllByFirstName(String firstName); + List findAllByLastName(String lastName); + List findAllByMiddleName(String middleName); + List findAllByFirstNameAndLastName(String firstName, String lastName); + List findAllByFirstNameAndMiddleNameAndLastName(String firstName, String middleName, String lastName); + List findAllByDateOfBirth(LocalDate dateOfBirth); + List findAllByCaste(String caste); + List findAllByCategory(String category); + List findAllByReligion(String religion); + Student findByAadharNumber(String aadharNumber); }