#can't understand how to write function from description

1 messages · Page 1 of 1 (latest)

toxic kiln
#

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]

  1. If present, it is not changed
  2. If not, a new record is added
  3. 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);
                }
            }
        });

mild minnowBOT
#

<@&987246399047479336> please have a look, thanks.

mild minnowBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.