Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payam #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
<artifactId>mysql-connector-java</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";

}
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/coddicted/school/student/model/Address.java
Original file line number Diff line number Diff line change
@@ -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;
}
21 changes: 21 additions & 0 deletions src/main/java/com/coddicted/school/student/model/AddressType.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/coddicted/school/student/model/Email.java
Original file line number Diff line number Diff line change
@@ -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;
}
22 changes: 22 additions & 0 deletions src/main/java/com/coddicted/school/student/model/EmailType.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
21 changes: 21 additions & 0 deletions src/main/java/com/coddicted/school/student/model/Gender.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
34 changes: 34 additions & 0 deletions src/main/java/com/coddicted/school/student/model/Person.java
Original file line number Diff line number Diff line change
@@ -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<Email> getEmailList();
void setEmailList(List<Email> emailList);

List<Phone> getPhoneList();
void setPhoneList(List<Phone> phoneList);

List<Address> getAddressList();
void setAddressList(List<Address> addressList);
}
12 changes: 12 additions & 0 deletions src/main/java/com/coddicted/school/student/model/Phone.java
Original file line number Diff line number Diff line change
@@ -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;
}
27 changes: 27 additions & 0 deletions src/main/java/com/coddicted/school/student/model/PhoneType.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
50 changes: 29 additions & 21 deletions src/main/java/com/coddicted/school/student/model/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have a field for student's class?

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@ApiModelProperty(notes = SwaggerConstant.AUTO_GENERATED_STUDENT_ID)
private Integer id;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this ID field removed? This is also causing compilation error.

@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<Phone> phoneList;

@ApiModelProperty(notes = SwaggerConstant.STUDENT_EMAIL_LIST)
private List<Email> emailList;

@ApiModelProperty(notes = SwaggerConstant.STUDENT_ADDRESS_LIST)
private List<Address> addressList;

@ApiModelProperty(notes = SwaggerConstant.STUDENT_RELIGION)
private String religion;
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<Student, Integer>
public interface StudentRepository extends MongoRepository<Student, String>
{
List<Student> findAll();
List<Student> findAllByFirstName(String firstName);
List<Student> findAllByLastName(String lastName);
List<Student> findAllByMiddleName(String middleName);
List<Student> findAllByFirstNameAndLastName(String firstName, String lastName);
List<Student> findAllByFirstNameAndMiddleNameAndLastName(String firstName, String middleName, String lastName);
List<Student> findAllByDateOfBirth(LocalDate dateOfBirth);
List<Student> findAllByCaste(String caste);
List<Student> findAllByCategory(String category);
List<Student> findAllByReligion(String religion);

Student findByAadharNumber(String aadharNumber);
}