Skip to content

Commit 63c6925

Browse files
kruschebassner
andauthored
Update src/main/java/de/tum/cit/aet/artemis/lecture/web/LectureResource.java
Co-authored-by: Patrick Bassner <[email protected]>
1 parent adcf418 commit 63c6925

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/main/java/de/tum/cit/aet/artemis/lecture/web/LectureResource.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,24 @@ public ResponseEntity<List<LectureDTO>> getLecturesWithSlidesForCourse(@PathVari
230230
// Group slides by attachment unit id to combine them into the DTOs
231231
Map<Long, List<SlideDTO>> slidesByAttachmentUnitId = slides.stream().collect(Collectors.groupingBy(SlideDTO::attachmentUnitId));
232232
// Convert visible lectures to DTOs (filtering active attachments) and add non hidden slides to the DTOs
233-
List<LectureDTO> lectureDTOs = lectures.stream().map(LectureDTO::from).peek(lectureDTO -> {
234-
List<AttachmentUnitDTO> attachmentUnitDTOs = lectureDTO.lectureUnits;
235-
for (AttachmentUnitDTO attachmentUnitDTO : attachmentUnitDTOs) {
233+
List<LectureDTO> lectureDTOs = lectures.stream()
234+
.map(LectureDTO::from)
235+
.sorted(Comparator.comparingLong(LectureDTO::id))
236+
.toList();
237+
238+
lectureDTOs.forEach(lectureDTO -> {
239+
for (AttachmentUnitDTO attachmentUnitDTO : lectureDTO.lectureUnits) {
236240
List<SlideDTO> slidesForAttachmentUnit = slidesByAttachmentUnitId.get(attachmentUnitDTO.id);
237241
if (slidesForAttachmentUnit != null) {
238242
// remove unnecessary fields from the slide DTOs
239-
var finalSlides = slidesForAttachmentUnit.stream().map(slideDTO -> new SlideDTO(slideDTO.id(), slideDTO.slideNumber(), null, null))
240-
.sorted(Comparator.comparingInt(SlideDTO::slideNumber)).toList();
243+
var finalSlides = slidesForAttachmentUnit.stream()
244+
.map(slideDTO -> new SlideDTO(slideDTO.id(), slideDTO.slideNumber(), null, null))
245+
.sorted(Comparator.comparingInt(SlideDTO::slideNumber))
246+
.toList();
241247
attachmentUnitDTO.slides.addAll(finalSlides);
242248
}
243249
}
244-
}).sorted(Comparator.comparingLong(LectureDTO::id)).toList();
250+
});
245251

246252
log.info(" Finished getting all lectures with slides in {}ms", System.currentTimeMillis() - start);
247253
return ResponseEntity.ok().body(lectureDTOs);

0 commit comments

Comments
 (0)