diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/Students.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/Students.java new file mode 100644 index 0000000..4086ce3 --- /dev/null +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/Students.java @@ -0,0 +1,22 @@ +package nl.andrewlalis.teaching_assistant_assistant.controllers; + +import nl.andrewlalis.teaching_assistant_assistant.model.repositories.StudentRepository; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class Students { + + private StudentRepository studentRepository; + + protected Students(StudentRepository studentRepository) { + this.studentRepository = studentRepository; + } + + @GetMapping("/students") + public String get(Model model) { + model.addAttribute("students", this.studentRepository.findAll()); + return "students"; + } +} diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/CourseEntity.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/CourseEntity.java new file mode 100644 index 0000000..612d8ca --- /dev/null +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/CourseEntity.java @@ -0,0 +1,70 @@ +package nl.andrewlalis.teaching_assistant_assistant.controllers.courses; + +import nl.andrewlalis.teaching_assistant_assistant.model.Course; +import nl.andrewlalis.teaching_assistant_assistant.model.repositories.CourseRepository; +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 for the course entity, that is, one individual course. + */ +@Controller +public class CourseEntity { + + private CourseRepository courseRepository; + + protected CourseEntity(CourseRepository courseRepository) { + this.courseRepository = courseRepository; + } + + /** + * Handles get requests to a course with a given code. + * @param code The unique course code used to identify a course entity. + * @param model The view model that will be populated with data. + * @return The template which will be used in conjunction with the model to build a view. + */ + @GetMapping("/courses/{code}") + public String get(@PathVariable String code, Model model) { + this.addCourseToModelIfExists(code, model); + return "courses/entity"; + } + + /** + * Gets the student teams for a particular course. + * @param code The course code. + * @param model The view model. + * @return The template for viewing the list of student teams. + */ + @GetMapping("/courses/{code}/student_teams") + public String getStudentTeams(@PathVariable String code, Model model) { + this.addCourseToModelIfExists(code, model); + return "courses/entity/student_teams"; + } + + /** + * Gets the students for a particular course. + * @param code The course code. + * @param model The view model. + * @return The template for viewing the list of students. + */ + @GetMapping("/courses/{code}/students") + public String getStudents(@PathVariable String code, Model model) { + this.addCourseToModelIfExists(code, model); + return "courses/entity/students"; + } + + /** + * Adds the course found by a certain code to the list of model attributes. + * @param courseCode The unique code used to identify this course. + * @param model The view model to add the course data to. + */ + private void addCourseToModelIfExists(String courseCode, Model model) { + Optional courseOptional = this.courseRepository.findByCode(courseCode); + courseOptional.ifPresent(course -> model.addAttribute("course", course)); + } + +} diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/Entity.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/Entity.java deleted file mode 100644 index 8bc8d33..0000000 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/Entity.java +++ /dev/null @@ -1,42 +0,0 @@ -package nl.andrewlalis.teaching_assistant_assistant.controllers.courses; - -import nl.andrewlalis.teaching_assistant_assistant.model.Course; -import nl.andrewlalis.teaching_assistant_assistant.model.repositories.CourseRepository; -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 for the course entity, that is, one individual course. - */ -@Controller -public class Entity { - - private CourseRepository courseRepository; - - protected Entity(CourseRepository courseRepository) { - this.courseRepository = courseRepository; - } - - /** - * Handles get requests to a course with a given code. - * @param code The unique course code used to identify a course entity. - * @param model The view model that will be populated with data. - * @return The template which will be used in conjunction with the model to build a view. - */ - @GetMapping("/courses/{code}") - public String get(@PathVariable String code, Model model) { - Optional courseOptional = this.courseRepository.findByCode(code); - - if (courseOptional.isPresent()) { - Course course = courseOptional.get(); - model.addAttribute("course", course); - } - - return "courses/entity"; - } - -} diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/ImportStudents.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/entity/ImportStudents.java similarity index 94% rename from src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/ImportStudents.java rename to src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/entity/ImportStudents.java index b858d4c..65c5014 100644 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/ImportStudents.java +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/entity/ImportStudents.java @@ -1,4 +1,4 @@ -package nl.andrewlalis.teaching_assistant_assistant.controllers.courses; +package nl.andrewlalis.teaching_assistant_assistant.controllers.courses.entity; import nl.andrewlalis.teaching_assistant_assistant.model.Course; import nl.andrewlalis.teaching_assistant_assistant.model.people.teams.StudentTeam; @@ -40,7 +40,7 @@ public class ImportStudents { public String get(@PathVariable String code, Model model) { Optional optionalCourse = this.courseRepository.findByCode(code); optionalCourse.ifPresent(course -> model.addAttribute("course", course)); - return "courses/import_students"; + return "courses/entity/import_students"; } @PostMapping( @@ -74,10 +74,10 @@ public class ImportStudents { team.setCourse(course); course.addStudentTeam(team); - //this.studentRepository.saveAll((team.getMembers())); + this.studentRepository.saveAll(team.getStudents()); }); - //this.studentTeamRepository.saveAll(studentTeams); + this.studentTeamRepository.saveAll(studentTeams); this.courseRepository.save(course); diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/entity/student_teams/GenerateRepositories.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/entity/student_teams/GenerateRepositories.java new file mode 100644 index 0000000..a3aa0bc --- /dev/null +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/entity/student_teams/GenerateRepositories.java @@ -0,0 +1,39 @@ +package nl.andrewlalis.teaching_assistant_assistant.controllers.courses.entity.student_teams; + +import nl.andrewlalis.teaching_assistant_assistant.model.Course; +import nl.andrewlalis.teaching_assistant_assistant.model.repositories.CourseRepository; +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 java.util.Optional; + +@Controller +public class GenerateRepositories { + + private CourseRepository courseRepository; + + protected GenerateRepositories(CourseRepository courseRepository) { + this.courseRepository = courseRepository; + } + + @GetMapping("/courses/{courseCode}/student_teams/generate_repositories") + public String get(@PathVariable String courseCode, Model model) { + Optional optionalCourse = this.courseRepository.findByCode(courseCode); + optionalCourse.ifPresent(course -> model.addAttribute("course", course)); + + return "courses/entity/student_teams/generate_repositories"; + } + + @PostMapping( + value = "/courses/{courseCode}/student_teams/generate_repositories", + consumes = "application/x-www-form-urlencoded" + ) + public String post(@PathVariable String courseCode) { + System.out.println("Post received for " + courseCode); + + return "redirect:/courses/{courseCode}"; + } +} diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/entity/student_teams/StudentTeamEntity.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/entity/student_teams/StudentTeamEntity.java new file mode 100644 index 0000000..aeae752 --- /dev/null +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/entity/student_teams/StudentTeamEntity.java @@ -0,0 +1,35 @@ +package nl.andrewlalis.teaching_assistant_assistant.controllers.courses.entity.student_teams; + +import nl.andrewlalis.teaching_assistant_assistant.model.people.teams.StudentTeam; +import nl.andrewlalis.teaching_assistant_assistant.model.repositories.StudentTeamRepository; +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 StudentTeamEntity { + + private StudentTeamRepository studentTeamRepository; + + protected StudentTeamEntity(StudentTeamRepository studentTeamRepository) { + this.studentTeamRepository = studentTeamRepository; + } + + /** + * Gets data for a specific student team. + * @param courseCode The course code for the course in which the team resides. + * @param teamId The id of the team. + * @param model The view model. + * @return The name of the template which will be used to view the student team. + */ + @GetMapping("/courses/{courseCode}/student_teams/{teamId}") + public String get(@PathVariable String courseCode, @PathVariable int teamId, Model model) { + Optional optionalStudentTeam = this.studentTeamRepository.findByCourseCodeAndId(courseCode, teamId); + optionalStudentTeam.ifPresent(team -> model.addAttribute("student_team", team)); + + return "courses/entity/student_teams/entity"; + } +} diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/students/StudentEntity.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/students/StudentEntity.java new file mode 100644 index 0000000..db914de --- /dev/null +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/students/StudentEntity.java @@ -0,0 +1,27 @@ +package nl.andrewlalis.teaching_assistant_assistant.controllers.students; + +import nl.andrewlalis.teaching_assistant_assistant.model.people.Student; +import nl.andrewlalis.teaching_assistant_assistant.model.repositories.StudentRepository; +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 StudentEntity { + + private StudentRepository studentRepository; + + protected StudentEntity(StudentRepository studentRepository) { + this.studentRepository = studentRepository; + } + + @GetMapping("/students/{id}") + public String get(@PathVariable long id, Model model) { + Optional optionalStudent = this.studentRepository.findById(id); + optionalStudent.ifPresent(student -> model.addAttribute("student", student)); + return "students/entity"; + } +} 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 fd1879d..058984c 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 @@ -31,6 +31,12 @@ public class Course extends BasicEntity { @Column(unique = true, nullable = false) private String code; + /** + * The github organization name for this course, if any. + */ + @Column + private String githubOrganizationName; + /** * The list of assignments this course contains. */ @@ -119,6 +125,14 @@ public class Course extends BasicEntity { return code; } + public String getGithubOrganizationName() { + return this.githubOrganizationName; + } + + public void setGithubOrganizationName(String name) { + this.githubOrganizationName = name; + } + public List getAssignments() { return assignments; } diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/teams/StudentTeam.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/teams/StudentTeam.java index f4be0fc..d323e49 100644 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/teams/StudentTeam.java +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/teams/StudentTeam.java @@ -4,6 +4,7 @@ import nl.andrewlalis.teaching_assistant_assistant.model.assignments.grades.Assi import nl.andrewlalis.teaching_assistant_assistant.model.people.Person; import nl.andrewlalis.teaching_assistant_assistant.model.people.Student; +import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.OneToMany; @@ -16,6 +17,12 @@ import java.util.List; @Entity public class StudentTeam extends Team { + /** + * The name of the github repository that belongs to this team. + */ + @Column + private String githubRepositoryName; + /** * The list of assignment grades which this student group has received. */ @@ -38,4 +45,12 @@ public class StudentTeam extends Team { return students; } + public String getGithubRepositoryName() { + return this.githubRepositoryName; + } + + public void setGithubRepositoryName(String name) { + this.githubRepositoryName = name; + } + } diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/repositories/StudentTeamRepository.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/repositories/StudentTeamRepository.java index f0b5250..1800848 100644 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/repositories/StudentTeamRepository.java +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/repositories/StudentTeamRepository.java @@ -3,5 +3,8 @@ package nl.andrewlalis.teaching_assistant_assistant.model.repositories; import nl.andrewlalis.teaching_assistant_assistant.model.people.teams.StudentTeam; import org.springframework.data.repository.CrudRepository; +import java.util.Optional; + public interface StudentTeamRepository extends CrudRepository { + Optional findByCourseCodeAndId(String courseCode, long id); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 57daaf2..37dd396 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,4 +1,4 @@ -spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.hibernate.ddl-auto=update spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL57Dialect spring.datasource.username=root spring.datasource.password=root @@ -11,3 +11,5 @@ spring.datasource.url=jdbc:mysql://localhost:3306/teaching_assistant_assistant?s spring.security.user.name=tester spring.security.user.password=tester + +spring.data.rest.e diff --git a/src/main/resources/templates/courses/create.html b/src/main/resources/templates/courses/create.html index 657a140..a90b098 100644 --- a/src/main/resources/templates/courses/create.html +++ b/src/main/resources/templates/courses/create.html @@ -14,6 +14,8 @@ + + diff --git a/src/main/resources/templates/courses/entity.html b/src/main/resources/templates/courses/entity.html index 4933903..fb2c3e2 100644 --- a/src/main/resources/templates/courses/entity.html +++ b/src/main/resources/templates/courses/entity.html @@ -10,53 +10,20 @@

(Code: )


-

Teaching Assistant Groups ():

- - - - - -
- - TA Team - - - -
- -

Student Groups ():

- - - - - -
- - Student Team - - - -
- -

All Students ():

- - - - - - - -
- - Student - -
+