Hello! I'm struggling to put this thing into a function to check all 3. I'm trying to replicate this in a unit test but can't seem to progress anywhere.
For each repairTeamUserIds value, a check is made for records found where Repair_team_user.USER_ID = repairTeamUserIds[n]
- If present, it is not changed
- If not, a new record is added
- If there is a record in the database with a Repair_team_user.USER_ID value that is not found in the repairTeamUserIds list, the record is deleted from the database
final var repairTeams = new ArrayList<>(List.of(1, 2, 3));
final var repairTeamUserIds = new ArrayList<>(List.of(1, 2, 4));
request.getRepairTeamUserIds().forEach(userId -> {
for (RepairTeam repairTeam : repairTeams) {
if (!Objects.equals(userId, repairTeam.getUser().getId())) {
repairTeamRepository.delete(repairTeam);
} else {
final var newRepairTeam = new RepairTeam();
newRepairTeam.setRepair(repair);
newRepairTeam.setUser(user);
repairTeamRepository.save(newRepairTeam);
}
}
});