diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/TeachingAssistantAssistantApplication.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/TeachingAssistantAssistantApplication.java index 4728148..cc75294 100644 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/TeachingAssistantAssistantApplication.java +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/TeachingAssistantAssistantApplication.java @@ -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")); } } diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/BasicEntity.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/BasicEntity.java index 38db40a..ea24a13 100644 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/BasicEntity.java +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/BasicEntity.java @@ -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; + } } diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/Course.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/Course.java index 1e904a0..9945b0c 100644 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/Course.java +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/Course.java @@ -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 teachingAssistants; diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/Person.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/Person.java index e07f65b..e881785 100644 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/Person.java +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/Person.java @@ -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; + } } diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/Student.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/Student.java index a23ce54..ac95e96 100644 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/Student.java +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/Student.java @@ -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 courses; + /** + * Default constructor for JPA. + */ + protected Student() {} public Student(String firstName, String lastName, String emailAddress) { super(firstName, lastName, emailAddress); diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/TeachingAssistant.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/TeachingAssistant.java index 35685a9..5208f8a 100644 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/TeachingAssistant.java +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/TeachingAssistant.java @@ -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 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 sectionGrades; + @Column + private TeachingAssistantRole role; + + /** + * Default constructor for JPA. + */ + protected TeachingAssistant() {} + } diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/TeachingAssistantRole.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/TeachingAssistantRole.java new file mode 100644 index 0000000..e063029 --- /dev/null +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/TeachingAssistantRole.java @@ -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 +} diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/groups/Group.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/groups/Group.java new file mode 100644 index 0000000..dc1a0ae --- /dev/null +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/groups/Group.java @@ -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

The type of members this group contains. + */ +@MappedSuperclass +public abstract class Group

extends BasicEntity { + + /** + * The list of members in this group. + */ + @OneToMany( + fetch = FetchType.EAGER, + orphanRemoval = true + ) + protected List

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

getMembers() { + return this.members; + } + +} diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/groups/StudentGroup.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/groups/StudentGroup.java new file mode 100644 index 0000000..36d7360 --- /dev/null +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/groups/StudentGroup.java @@ -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 { + + /** + * Default constructor for JPA. + */ + public StudentGroup() {} + +} diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/groups/TeachingAssistantGroup.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/groups/TeachingAssistantGroup.java new file mode 100644 index 0000000..1147763 --- /dev/null +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/groups/TeachingAssistantGroup.java @@ -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 { + + /** + * Default constructor for JPA. + */ + public TeachingAssistantGroup() {} + +} diff --git a/src/main/resources/templates/courses.html b/src/main/resources/templates/courses.html index 7315dfc..f5df6be 100644 --- a/src/main/resources/templates/courses.html +++ b/src/main/resources/templates/courses.html @@ -10,12 +10,14 @@ Name Code + Created at +