Skip to content

Commit

Permalink
fix: Delete exam rows when procedure switch to 3
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveGT96 committed Oct 22, 2024
1 parent f461d06 commit ed898e2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/java/org/isf/exa/service/ExamIoOperations.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,15 @@ public Exam create(Exam payload, List<String> rows) throws OHServiceException {
*/
@Transactional
public Exam update(Exam payload, List<String> rows) throws OHServiceException {
Exam oldExam = findByCode(payload.getCode());
Exam exam = repository.save(payload);
List<ExamRow> examRows = rowRepository.findAllByExam_CodeOrderByDescription(exam.getCode());
if (exam.getProcedure() == 3) {
if (oldExam.getProcedure() != 3) {
rowRepository.deleteAll(examRows);
}
return exam;
}
List<ExamRow> examRows = rowRepository.findAllByExam_CodeOrderByDescription(exam.getCode());
List<ExamRow> rowsToRemove = examRows.stream().filter(examRow -> !rows.contains(examRow.getDescription())).toList();
List<ExamRow> rowsToAdd = rows.stream().filter(row -> examRows.stream().noneMatch(examRow -> Objects.equals(row, examRow.getDescription())))
.map(description -> new ExamRow(exam, description)).toList();
Expand Down

0 comments on commit ed898e2

Please sign in to comment.