Skip to content

Commit

Permalink
hotfix: device id null
Browse files Browse the repository at this point in the history
  • Loading branch information
jcw1031 committed May 5, 2024
1 parent 7ca1b82 commit 3142e56
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/main/java/ac/knu/likeknu/service/AnnouncementService.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public List<AnnouncementListResponse> getAnnouncements(Campus campus, Category c
PageRequest pageRequest = PageRequest.of(requestPage, DEFAULT_ANNOUNCEMENT_PAGE_SIZE,
Sort.by(Order.desc("announcementDate"), Order.desc("collectedAt")));

Device device = deviceRepository.findById(nativeDeviceId)
.orElseThrow(() -> new BusinessException(String.format("Device not found! [%s]", nativeDeviceId)));
Page<Announcement> announcementsPage;
if (keyword != null && !keyword.isEmpty()) {
announcementsPage = announcementRepository.findByCampusInAndCategoryAndAnnouncementTitleContains(
Expand All @@ -54,8 +52,16 @@ public List<AnnouncementListResponse> getAnnouncements(Campus campus, Category c

pageDto.updateTotalPages(announcementsPage.getTotalPages());
pageDto.updateTotalElements(announcementsPage.getTotalElements());

if (nativeDeviceId != null) {
Device device = deviceRepository.findById(nativeDeviceId)
.orElseThrow(() -> new BusinessException(String.format("Device not found! [%s]", nativeDeviceId)));
return announcementsPage.stream()
.map(announcement -> AnnouncementListResponse.of(announcement, device.getBookmarks()))
.toList();
}
return announcementsPage.stream()
.map(announcement -> AnnouncementListResponse.of(announcement, device.getBookmarks()))
.map(AnnouncementListResponse::of)
.toList();
}

Expand Down

0 comments on commit 3142e56

Please sign in to comment.