From 643124f2426381445981c3999ecb06a3ecb2d1d8 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Mon, 13 May 2019 11:50:37 +0200 Subject: [PATCH] Fixed duplicate error, added debug messages. --- .../services/StudentService.java | 3 +-- .../services/StudentTeamService.java | 12 +++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/services/StudentService.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/services/StudentService.java index 70415aa..5e77fba 100644 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/services/StudentService.java +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/services/StudentService.java @@ -35,8 +35,7 @@ public class StudentService { if (course != null) { course.addParticipant(student); student.assignToCourse(course); - this.courseRepository.save(course); - this.studentRepository.save(student); + this.courseRepository.save(course); // This cascades to save the student as well. } } diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/services/StudentTeamService.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/services/StudentTeamService.java index 24f29a2..db65485 100644 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/services/StudentTeamService.java +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/services/StudentTeamService.java @@ -50,7 +50,7 @@ public class StudentTeamService { StudentTeam newTeam = new StudentTeam(course); course.addStudentTeam(newTeam); this.courseRepository.save(course); - logger.info("Created new team: " + newTeam.getId()); + logger.info("Created new team."); return newTeam; } @@ -185,13 +185,19 @@ public class StudentTeamService { s.removeFromAssignedTeam(team); team.removeMember(s); this.studentRepository.save(s); + + logger.debug("Removed student " + s.getFullName() + " from team " + team.getId()); } // Remove the TA team assignment. TeachingAssistantTeam teachingAssistantTeam = team.getAssignedTeachingAssistantTeam(); - teachingAssistantTeam.removeAssignedStudentTeam(team); + if (teachingAssistantTeam != null) { + teachingAssistantTeam.removeAssignedStudentTeam(team); + this.teachingAssistantTeamRepository.save(teachingAssistantTeam); + logger.debug("Removed team " + team.getId() + " from Teaching Assistant Team " + teachingAssistantTeam.getId() + " assigned teams list."); + } + team.setAssignedTeachingAssistantTeam(null); - this.teachingAssistantTeamRepository.save(teachingAssistantTeam); // Remove the repository from the course and delete it. course.removeStudentTeam(team);