diff --git a/src/main/java/ac/knu/likeknu/service/AnnouncementService.java b/src/main/java/ac/knu/likeknu/service/AnnouncementService.java index a59f544..3c67897 100644 --- a/src/main/java/ac/knu/likeknu/service/AnnouncementService.java +++ b/src/main/java/ac/knu/likeknu/service/AnnouncementService.java @@ -39,8 +39,6 @@ public List 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 announcementsPage; if (keyword != null && !keyword.isEmpty()) { announcementsPage = announcementRepository.findByCampusInAndCategoryAndAnnouncementTitleContains( @@ -54,8 +52,16 @@ public List 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(); }