Added group models
This commit is contained in:
parent
7da626fb9b
commit
61de43d7d8
|
@ -1,6 +1,8 @@
|
|||
package nl.andrewlalis.teaching_assistant_assistant;
|
||||
|
||||
import nl.andrewlalis.teaching_assistant_assistant.model.Course;
|
||||
import nl.andrewlalis.teaching_assistant_assistant.model.people.Student;
|
||||
import nl.andrewlalis.teaching_assistant_assistant.model.people.groups.StudentGroup;
|
||||
import nl.andrewlalis.teaching_assistant_assistant.model.repositories.CourseRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
|
@ -25,5 +27,7 @@ public class TeachingAssistantAssistantApplication implements CommandLineRunner
|
|||
courseRepository.save(new Course("Program Correctness", "PC-002"));
|
||||
System.out.println("Saved two courses.");
|
||||
System.out.println("Course count: " + courseRepository.count());
|
||||
StudentGroup sg = new StudentGroup();
|
||||
sg.addMember(new Student("Andrew", "Lalis", "andrewlalisofficial@gmail.com"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,4 +35,17 @@ public abstract class BasicEntity {
|
|||
return this.createdOn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Two entities are equal if they have the same id.
|
||||
* @param o The other object.
|
||||
* @return True if the entities are the same, or false if not.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof BasicEntity) {
|
||||
BasicEntity other = (BasicEntity) o;
|
||||
return other.id.equals(this.id);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,9 +45,9 @@ public class Course extends BasicEntity {
|
|||
*/
|
||||
@ManyToMany
|
||||
@JoinTable(
|
||||
name = "course_teachingAssistant",
|
||||
name = "course_teaching_assistant",
|
||||
joinColumns = @JoinColumn(name = "course_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "teachingAssistant_id")
|
||||
inverseJoinColumns = @JoinColumn(name = "teaching_assistant_id")
|
||||
)
|
||||
private List<TeachingAssistant> teachingAssistants;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package nl.andrewlalis.teaching_assistant_assistant.model.people;
|
||||
|
||||
import nl.andrewlalis.teaching_assistant_assistant.model.BasicEntity;
|
||||
import nl.andrewlalis.teaching_assistant_assistant.model.people.groups.Group;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
|
@ -22,6 +23,11 @@ public abstract class Person extends BasicEntity {
|
|||
@Column
|
||||
private String emailAddress;
|
||||
|
||||
@ManyToOne(
|
||||
fetch = FetchType.LAZY
|
||||
)
|
||||
private Group<?> group;
|
||||
|
||||
/**
|
||||
* Default constructor for JPA.
|
||||
*/
|
||||
|
@ -39,4 +45,23 @@ public abstract class Person extends BasicEntity {
|
|||
this.emailAddress = emailAddress;
|
||||
}
|
||||
|
||||
/*
|
||||
Getters and Setters
|
||||
*/
|
||||
|
||||
public String getFirstName() {
|
||||
return this.firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return this.lastName;
|
||||
}
|
||||
|
||||
public String getEmailAddress() {
|
||||
return this.emailAddress;
|
||||
}
|
||||
|
||||
public Group<?> getGroup() {
|
||||
return this.group;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
package nl.andrewlalis.teaching_assistant_assistant.model.people;
|
||||
|
||||
import nl.andrewlalis.teaching_assistant_assistant.model.Course;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents a student, or someone enrolled and submitting assignments for a course.
|
||||
|
@ -8,7 +14,21 @@ import javax.persistence.Entity;
|
|||
@Entity
|
||||
public class Student extends Person {
|
||||
|
||||
/**
|
||||
* The list of courses which this student is taking part in.
|
||||
*/
|
||||
@ManyToMany
|
||||
@JoinTable(
|
||||
name = "course_student",
|
||||
joinColumns = @JoinColumn(name = "student_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "course_id")
|
||||
)
|
||||
private List<Course> courses;
|
||||
|
||||
/**
|
||||
* Default constructor for JPA.
|
||||
*/
|
||||
protected Student() {}
|
||||
|
||||
public Student(String firstName, String lastName, String emailAddress) {
|
||||
super(firstName, lastName, emailAddress);
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package nl.andrewlalis.teaching_assistant_assistant.model.people;
|
||||
|
||||
import nl.andrewlalis.teaching_assistant_assistant.model.Course;
|
||||
import nl.andrewlalis.teaching_assistant_assistant.model.assignments.grades.SectionGrade;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -13,6 +12,17 @@ import java.util.List;
|
|||
@Entity
|
||||
public class TeachingAssistant extends Person {
|
||||
|
||||
/**
|
||||
* The list of courses which this teaching assistant is a member of.
|
||||
*/
|
||||
@ManyToMany
|
||||
@JoinTable(
|
||||
name = "course_teaching_assistant",
|
||||
joinColumns = @JoinColumn(name = "teaching_assistant_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "course_id")
|
||||
)
|
||||
private List<Course> courses;
|
||||
|
||||
/**
|
||||
* The list of all feedback given by a teaching assistant.
|
||||
*/
|
||||
|
@ -20,4 +30,12 @@ public class TeachingAssistant extends Person {
|
|||
@JoinColumn(name = "teaching_assistant_id")
|
||||
private List<SectionGrade> sectionGrades;
|
||||
|
||||
@Column
|
||||
private TeachingAssistantRole role;
|
||||
|
||||
/**
|
||||
* Default constructor for JPA.
|
||||
*/
|
||||
protected TeachingAssistant() {}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package nl.andrewlalis.teaching_assistant_assistant.model.people;
|
||||
|
||||
/**
|
||||
* Defines several types of Teaching Assistant roles for specialization.
|
||||
*/
|
||||
public enum TeachingAssistantRole {
|
||||
GENERAL,
|
||||
ORGANIZER,
|
||||
TECHNICAL,
|
||||
CORRESPONDENT
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package nl.andrewlalis.teaching_assistant_assistant.model.people.groups;
|
||||
|
||||
import nl.andrewlalis.teaching_assistant_assistant.model.BasicEntity;
|
||||
import nl.andrewlalis.teaching_assistant_assistant.model.people.Person;
|
||||
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.OneToMany;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A group consisting of one or more members. Child classes should define P as a sub class of Person to define custom
|
||||
* behavior if needed.
|
||||
* @param <P> The type of members this group contains.
|
||||
*/
|
||||
@MappedSuperclass
|
||||
public abstract class Group<P extends Person> extends BasicEntity {
|
||||
|
||||
/**
|
||||
* The list of members in this group.
|
||||
*/
|
||||
@OneToMany(
|
||||
fetch = FetchType.EAGER,
|
||||
orphanRemoval = true
|
||||
)
|
||||
protected List<P> members;
|
||||
|
||||
public void addMember(P person) {
|
||||
this.members.add(person);
|
||||
}
|
||||
|
||||
public boolean containsMember(P person) {
|
||||
return this.members.contains(person);
|
||||
}
|
||||
|
||||
public void removeMember(P person) {
|
||||
this.members.remove(person);
|
||||
}
|
||||
|
||||
/*
|
||||
Getters and Setters
|
||||
*/
|
||||
|
||||
public List<P> getMembers() {
|
||||
return this.members;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package nl.andrewlalis.teaching_assistant_assistant.model.people.groups;
|
||||
|
||||
import nl.andrewlalis.teaching_assistant_assistant.model.people.Student;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
|
||||
/**
|
||||
* A group of students.
|
||||
*/
|
||||
@Entity
|
||||
public class StudentGroup extends Group<Student> {
|
||||
|
||||
/**
|
||||
* Default constructor for JPA.
|
||||
*/
|
||||
public StudentGroup() {}
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package nl.andrewlalis.teaching_assistant_assistant.model.people.groups;
|
||||
|
||||
import nl.andrewlalis.teaching_assistant_assistant.model.people.TeachingAssistant;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
|
||||
/**
|
||||
* A group of teaching assistants.
|
||||
*/
|
||||
@Entity
|
||||
public class TeachingAssistantGroup extends Group<TeachingAssistant> {
|
||||
|
||||
/**
|
||||
* Default constructor for JPA.
|
||||
*/
|
||||
public TeachingAssistantGroup() {}
|
||||
|
||||
}
|
|
@ -10,12 +10,14 @@
|
|||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Code</th>
|
||||
<th>Created at</th>
|
||||
</tr>
|
||||
<tr th:each="course: ${courses}">
|
||||
<td>
|
||||
<a th:href="@{/courses/{id}(id=${course.getId()})}" th:text="${course.getName()}"></a>
|
||||
</td>
|
||||
<td th:text="${course.getCode()}"></td>
|
||||
<td th:text="${course.getCreatedOn()}"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue