diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/TeachingAssistants.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/TeachingAssistants.java
new file mode 100644
index 0000000..821ad41
--- /dev/null
+++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/TeachingAssistants.java
@@ -0,0 +1,53 @@
+package nl.andrewlalis.teaching_assistant_assistant.controllers;
+
+import nl.andrewlalis.teaching_assistant_assistant.model.Course;
+import nl.andrewlalis.teaching_assistant_assistant.model.people.TeachingAssistant;
+import nl.andrewlalis.teaching_assistant_assistant.model.repositories.CourseRepository;
+import nl.andrewlalis.teaching_assistant_assistant.model.repositories.TeachingAssistantRepository;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+
+import java.util.Optional;
+
+@Controller
+public class TeachingAssistants {
+
+ private TeachingAssistantRepository teachingAssistantRepository;
+ private CourseRepository courseRepository;
+
+ protected TeachingAssistants(TeachingAssistantRepository teachingAssistantRepository, CourseRepository courseRepository) {
+ this.teachingAssistantRepository = teachingAssistantRepository;
+ this.courseRepository = courseRepository;
+ }
+
+ @GetMapping("/teaching_assistants")
+ public String get(Model model) {
+ model.addAttribute("teaching_assistants", teachingAssistantRepository.findAll());
+ return "teaching_assistants";
+ }
+
+ @GetMapping("/courses/{code}/teaching_assistants/create")
+ public String getCreate(@PathVariable String code, Model model) {
+ model.addAttribute("teachingAssistant", new TeachingAssistant("First Name", "Last Name", "github Username", "me@example.com"));
+ Optional optionalCourse = this.courseRepository.findByCode(code);
+ optionalCourse.ifPresent(course -> model.addAttribute("course", course));
+ return "courses/entity/teaching_assistants/create";
+ }
+
+ @PostMapping(
+ value = "/courses/{code}/teaching_assistants",
+ consumes = "application/x-www-form-urlencoded"
+ )
+ public String post(@PathVariable String code, @ModelAttribute("teachingAssistant") TeachingAssistant teachingAssistant) {
+ Optional optionalCourse = this.courseRepository.findByCode(code);
+ optionalCourse.ifPresent(course -> {
+ course.addParticipant(teachingAssistant);
+ this.courseRepository.save(course);
+ });
+ return "teaching_assistants/entity";
+ }
+}
diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/Create.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/CreateCourse.java
similarity index 88%
rename from src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/Create.java
rename to src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/CreateCourse.java
index 08376e2..7d8cd0d 100644
--- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/Create.java
+++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/CreateCourse.java
@@ -7,11 +7,11 @@ import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
-public class Create {
+public class CreateCourse {
private CourseRepository courseRepository;
- protected Create(CourseRepository courseRepository) {
+ protected CreateCourse(CourseRepository courseRepository) {
this.courseRepository = courseRepository;
}
diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/Generate.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/Generate.java
index c7f8ae5..2d5227b 100644
--- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/Generate.java
+++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/Generate.java
@@ -26,7 +26,7 @@ public class Generate {
this.courseRepository.saveAll(courses);
model.addAttribute("courses", courseRepository.findAll());
- return "courses";
+ return "redirect:/courses";
}
}
diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/entity/teaching_assistant_teams/CreateTeachingAssistantTeam.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/entity/teaching_assistant_teams/CreateTeachingAssistantTeam.java
new file mode 100644
index 0000000..542528d
--- /dev/null
+++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/entity/teaching_assistant_teams/CreateTeachingAssistantTeam.java
@@ -0,0 +1,75 @@
+package nl.andrewlalis.teaching_assistant_assistant.controllers.courses.entity.teaching_assistant_teams;
+
+import nl.andrewlalis.teaching_assistant_assistant.model.Course;
+import nl.andrewlalis.teaching_assistant_assistant.model.people.TeachingAssistant;
+import nl.andrewlalis.teaching_assistant_assistant.model.people.teams.TeachingAssistantTeam;
+import nl.andrewlalis.teaching_assistant_assistant.model.repositories.CourseRepository;
+import nl.andrewlalis.teaching_assistant_assistant.model.repositories.TeachingAssistantRepository;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import java.util.Optional;
+
+@Controller
+public class CreateTeachingAssistantTeam {
+
+ private CourseRepository courseRepository;
+ private TeachingAssistantRepository teachingAssistantRepository;
+
+ protected CreateTeachingAssistantTeam(CourseRepository courseRepository, TeachingAssistantRepository teachingAssistantRepository) {
+ this.courseRepository = courseRepository;
+ this.teachingAssistantRepository = teachingAssistantRepository;
+ }
+
+ @GetMapping("/courses/{code}/teaching_assistant_teams/create")
+ public String get(@PathVariable String code, Model model) {
+ Optional optionalCourse = this.courseRepository.findByCode(code);
+ optionalCourse.ifPresent(course -> model.addAttribute("course", course));
+ return "courses/entity/teaching_assistant_teams/create";
+ }
+
+ @PostMapping(
+ value = "/courses/{code}/teaching_assistant_teams",
+ consumes = "application/x-www-form-urlencoded"
+ )
+ public String post(
+ @PathVariable String code,
+ @RequestParam(value = "github_team_name") String githubTeamName,
+ @RequestParam(value = "id_1") long id1,
+ @RequestParam(value = "id_2") long id2,
+ Model model
+ ) {
+ TeachingAssistantTeam team = new TeachingAssistantTeam();
+ team.setGithubTeamName(githubTeamName);
+
+ Optional optionalCourse = this.courseRepository.findByCode(code);
+ Optional optionalTeachingAssistant1 = this.teachingAssistantRepository.findById(id1);
+ Optional optionalTeachingAssistant2 = this.teachingAssistantRepository.findById(id2);
+
+ System.out.println("Course code: " + code + ", Team name: " + githubTeamName + ", TA 1: " + id1 + ", TA 2: " + id2);
+
+ if (optionalCourse.isPresent() && optionalTeachingAssistant1.isPresent() && optionalTeachingAssistant2.isPresent()) {
+ System.out.println("All data available.");
+ Course course = optionalCourse.get();
+ team.setCourse(course);
+
+ team.addMember(optionalTeachingAssistant1.get());
+ team.addMember(optionalTeachingAssistant2.get());
+
+ course.addTeachingAssistantTeam(team);
+ this.courseRepository.save(course);
+
+ model.addAttribute("course", course);
+
+ return "courses/entity/teaching_assistant_teams";
+ } else {
+ System.out.println("Missing data!");
+ }
+
+ return "redirect:/courses/entity";
+ }
+}
diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/entity/teaching_assistant_teams/TeachingAssistantTeamEntity.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/entity/teaching_assistant_teams/TeachingAssistantTeamEntity.java
new file mode 100644
index 0000000..5923980
--- /dev/null
+++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/entity/teaching_assistant_teams/TeachingAssistantTeamEntity.java
@@ -0,0 +1,55 @@
+package nl.andrewlalis.teaching_assistant_assistant.controllers.courses.entity.teaching_assistant_teams;
+
+import nl.andrewlalis.teaching_assistant_assistant.model.Course;
+import nl.andrewlalis.teaching_assistant_assistant.model.people.teams.TeachingAssistantTeam;
+import nl.andrewlalis.teaching_assistant_assistant.model.repositories.CourseRepository;
+import nl.andrewlalis.teaching_assistant_assistant.model.repositories.TeachingAssistantTeamRepository;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+
+import java.util.Optional;
+
+@Controller
+public class TeachingAssistantTeamEntity {
+
+ private CourseRepository courseRepository;
+ private TeachingAssistantTeamRepository teachingAssistantTeamRepository;
+
+ protected TeachingAssistantTeamEntity(CourseRepository courseRepository, TeachingAssistantTeamRepository teachingAssistantTeamRepository) {
+ this.courseRepository = courseRepository;
+ this.teachingAssistantTeamRepository = teachingAssistantTeamRepository;
+ }
+
+ @GetMapping("/courses/{courseCode}/teaching_assistant_teams/{teamId}")
+ public String get(@PathVariable String courseCode, @PathVariable long teamId, Model model) {
+ Optional optionalCourse = this.courseRepository.findByCode(courseCode);
+ Optional optionalTeachingAssistantTeam = this.teachingAssistantTeamRepository.findById(teamId);
+
+ if (optionalCourse.isPresent() && optionalTeachingAssistantTeam.isPresent()) {
+ model.addAttribute("course", optionalCourse.get());
+ model.addAttribute("teachingAssistantTeam", optionalTeachingAssistantTeam.get());
+ }
+
+ return "courses/entity/teaching_assistant_teams/entity";
+ }
+
+ @GetMapping("/courses/{courseCode}/teaching_assistant_teams/{teamId}/delete")
+ public String delete(@PathVariable String courseCode, @PathVariable long teamId) {
+ Optional optionalCourse = this.courseRepository.findByCode(courseCode);
+ Optional optionalTeachingAssistantTeam = this.teachingAssistantTeamRepository.findById(teamId);
+
+ if (optionalCourse.isPresent() && optionalTeachingAssistantTeam.isPresent()) {
+ Course course = optionalCourse.get();
+ TeachingAssistantTeam team = optionalTeachingAssistantTeam.get();
+ course.removeTeachingAssistantTeam(team);
+
+ this.teachingAssistantTeamRepository.delete(team);
+ this.courseRepository.save(course);
+ }
+
+ return "redirect:/courses/entity/teaching_assistants";
+ }
+
+}
diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/teaching_assistants/TeachingAssistantEntity.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/teaching_assistants/TeachingAssistantEntity.java
new file mode 100644
index 0000000..99991b3
--- /dev/null
+++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/teaching_assistants/TeachingAssistantEntity.java
@@ -0,0 +1,41 @@
+package nl.andrewlalis.teaching_assistant_assistant.controllers.teaching_assistants;
+
+import nl.andrewlalis.teaching_assistant_assistant.model.people.TeachingAssistant;
+import nl.andrewlalis.teaching_assistant_assistant.model.repositories.TeachingAssistantRepository;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+
+import java.util.Optional;
+
+@Controller
+public class TeachingAssistantEntity {
+
+ private TeachingAssistantRepository teachingAssistantRepository;
+
+ protected TeachingAssistantEntity(TeachingAssistantRepository teachingAssistantRepository) {
+ this.teachingAssistantRepository = teachingAssistantRepository;
+ }
+
+ @GetMapping("/teaching_assistants/{id}")
+ public String get(@PathVariable long id, Model model) {
+ Optional optionalTeachingAssistant = this.teachingAssistantRepository.findById(id);
+ optionalTeachingAssistant.ifPresent(teachingAssistant -> model.addAttribute("teachingAssistant", teachingAssistant));
+ return "teaching_assistants/entity";
+ }
+
+ @GetMapping("/teaching_assistants/{id}/delete")
+ public String delete(@PathVariable long id) {
+ Optional optionalTeachingAssistant = this.teachingAssistantRepository.findById(id);
+ optionalTeachingAssistant.ifPresent(teachingAssistant -> {
+ teachingAssistant.getCourses().forEach(course -> course.removeParticipant(teachingAssistant));
+ teachingAssistant.getTeams().forEach(team -> {
+ team.removeMember(teachingAssistant);
+ });
+ this.teachingAssistantRepository.delete(teachingAssistant);
+ });
+
+ return "redirect:/teaching_assistants";
+ }
+}
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 4e65534..97a62f3 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
@@ -108,12 +108,20 @@ public class Course extends BasicEntity {
this.teachingAssistantTeams.add(team);
}
+ public void removeTeachingAssistantTeam(TeachingAssistantTeam team) {
+ this.teachingAssistantTeams.remove(team);
+ }
+
public void addParticipant(Person person) {
if (!this.participants.contains(person)) {
this.participants.add(person);
}
}
+ public void removeParticipant(Person person) {
+ this.participants.remove(person);
+ }
+
/*
Getters and Setters
*/
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 7909a7f..70245af 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
@@ -114,6 +114,10 @@ public abstract class Person extends BasicEntity {
return this.courses;
}
+ public List getTeams() {
+ return this.teams;
+ }
+
/**
* Determines if two Persons are equal. They are considered equal when all of the basic identifying information
* about the person is the same, regardless of case.
diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/repositories/TeachingAssistantRepository.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/repositories/TeachingAssistantRepository.java
new file mode 100644
index 0000000..63154c9
--- /dev/null
+++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/repositories/TeachingAssistantRepository.java
@@ -0,0 +1,7 @@
+package nl.andrewlalis.teaching_assistant_assistant.model.repositories;
+
+import nl.andrewlalis.teaching_assistant_assistant.model.people.TeachingAssistant;
+import org.springframework.data.repository.CrudRepository;
+
+public interface TeachingAssistantRepository extends CrudRepository {
+}
diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/repositories/TeachingAssistantTeamRepository.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/repositories/TeachingAssistantTeamRepository.java
new file mode 100644
index 0000000..a06552b
--- /dev/null
+++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/repositories/TeachingAssistantTeamRepository.java
@@ -0,0 +1,7 @@
+package nl.andrewlalis.teaching_assistant_assistant.model.repositories;
+
+import nl.andrewlalis.teaching_assistant_assistant.model.people.teams.TeachingAssistantTeam;
+import org.springframework.data.repository.CrudRepository;
+
+public interface TeachingAssistantTeamRepository extends CrudRepository {
+}
diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/github/GithubManager.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/github/GithubManager.java
index 5925a87..c314d8f 100644
--- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/github/GithubManager.java
+++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/github/GithubManager.java
@@ -10,6 +10,9 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
+/**
+ * Encapsulates much of the github functionality that is needed.
+ */
public class GithubManager {
private GitHub github;
diff --git a/src/main/resources/templates/courses/entity/teaching_assistant_teams.html b/src/main/resources/templates/courses/entity/teaching_assistant_teams.html
index aefe237..b1eb8b7 100644
--- a/src/main/resources/templates/courses/entity/teaching_assistant_teams.html
+++ b/src/main/resources/templates/courses/entity/teaching_assistant_teams.html
@@ -25,12 +25,20 @@
|
+
+
+ Delete
+
+ |
+
+
+
+ Create your course here
+
+
+
+
+
+
+
diff --git a/src/main/resources/templates/courses/entity/teaching_assistant_teams/create.html b/src/main/resources/templates/courses/entity/teaching_assistant_teams/create.html
new file mode 100644
index 0000000..b37e0d9
--- /dev/null
+++ b/src/main/resources/templates/courses/entity/teaching_assistant_teams/create.html
@@ -0,0 +1,37 @@
+
+
+