Skip to content

Commit

Permalink
[backend/frontend] Improv code
Browse files Browse the repository at this point in the history
  • Loading branch information
RomuDeuxfois committed Oct 2, 2024
1 parent 8d5e4b3 commit ea99f92
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,11 @@ private void getObjectives(Exercise duplicatedExercise, Exercise originalExercis

@Transactional(rollbackFor = Exception.class)
public Iterable<Team> removeTeams(@NotBlank final String exerciseId, @NotNull final List<String> teamIds) {
Exercise exercise = exerciseRepository.findById(exerciseId).orElseThrow(ElementNotFoundException::new);
Exercise exercise = this.exercise(exerciseId);
// Remove teams from exercise
List<Team> teams = this.exerciseRepository.teams(exercise.getId(), teamIds);
exercise.setTeams(fromIterable(teams));
this.exerciseRepository.save(exercise);
List<Team> teams = this.exerciseRepository.retrieveTeamsNotIn(exercise.getId(), teamIds);
exercise.setTeams(new ArrayList<>(teams));
this.updateExercise(exercise);
// Remove all association between users / exercises / teams
teamIds.forEach(exerciseTeamUserRepository::deleteTeamFromAllReferences);
// Remove all association between injects and teams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@ public Iterable<Team> addTeams(@NotBlank final String scenarioId, @NotNull final
@Transactional(rollbackFor = Exception.class)
public Iterable<Team> removeTeams(@NotBlank final String scenarioId, @NotNull final List<String> teamIds) {
Scenario scenario = this.scenario(scenarioId);
List<Team> teams = this.scenarioRepository.teams(scenario.getId(), teamIds);
// Remove teams from exercise
List<Team> teams = this.scenarioRepository.retrieveTeamsNotIn(scenario.getId(), teamIds);
scenario.setTeams(new ArrayList<>(teams));
this.updateScenario(scenario);
// Remove all association between users / exercises / teams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void testRemoveTeams() {
this.exerciseService.removeTeams(exerciseSaved.getId(), List.of(teamSaved.getId()));

// -- ASSERT --
List<Team> teams = this.exerciseRepository.teams(exerciseSaved.getId(), List.of(TEAM_ID));
List<Team> teams = this.exerciseRepository.retrieveTeamsNotIn(exerciseSaved.getId(), List.of(TEAM_ID));
assertEquals(0, teams.size());
Inject injectAssert = this.injectRepository.findById(INJECT_ID).orElseThrow();
assertEquals(0, injectAssert.getTeams().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void testRemoveTeams() {
this.scenarioService.removeTeams(scenarioSaved.getId(), List.of(teamSaved.getId()));

// -- ASSERT --
List<Team> teams = this.scenarioRepository.teams(scenarioSaved.getId(), List.of(TEAM_ID));
List<Team> teams = this.scenarioRepository.retrieveTeamsNotIn(scenarioSaved.getId(), List.of(TEAM_ID));
assertEquals(0, teams.size());
Inject injectAssert = this.injectRepository.findById(INJECT_ID).orElseThrow();
assertEquals(0, injectAssert.getTeams().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,6 @@ public interface ExerciseRepository extends JpaRepository<Exercise, String>,
+ "JOIN exercises_teams et ON t.team_id = et.team_id "
+ "WHERE et.exercise_id = :exerciseId "
+ " AND t.team_id NOT IN (:teamIds) ", nativeQuery = true)
List<Team> teams(@Param("exerciseId") final String exerciseId, @Param("teamIds") final List<String> teamIds);
List<Team> retrieveTeamsNotIn(@Param("exerciseId") final String exerciseId, @Param("teamIds") final List<String> teamIds);

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ public interface ScenarioRepository extends
+ "JOIN scenarios_teams st ON t.team_id = st.team_id "
+ "WHERE st.scenario_id = :scenarioId "
+ " AND t.team_id NOT IN (:teamIds) ", nativeQuery = true)
List<Team> teams(@Param("scenarioId") final String scenarioId, @Param("teamIds") final List<String> teamIds);
List<Team> retrieveTeamsNotIn(@Param("scenarioId") final String scenarioId, @Param("teamIds") final List<String> teamIds);

}

0 comments on commit ea99f92

Please sign in to comment.