diff --git a/src/main/java/ac/knu/likeknu/controller/AnnouncementController.java b/src/main/java/ac/knu/likeknu/controller/AnnouncementController.java index 62fece2..1d6aed0 100644 --- a/src/main/java/ac/knu/likeknu/controller/AnnouncementController.java +++ b/src/main/java/ac/knu/likeknu/controller/AnnouncementController.java @@ -55,11 +55,12 @@ public PageResponseDto> recentAnnouncementList( public PageResponseDto> searchAnnouncement( @RequestParam("campus") Campus campus, @RequestParam(name = "page", defaultValue = "1") int page, - @RequestParam(name = "keyword", required = false, defaultValue = "") String keyword + @RequestParam(name = "keyword", required = false, defaultValue = "") String keyword, + @RequestParam("deviceId") String deviceId ) { PageDto pageDto = PageDto.of(page); List announcements = - announcementService.searchAnnouncements(campus, pageDto, keyword.trim()); + announcementService.searchAnnouncements(campus, pageDto, keyword.trim(), deviceId); return PageResponseDto.of(announcements, pageDto); } } diff --git a/src/main/java/ac/knu/likeknu/service/AnnouncementService.java b/src/main/java/ac/knu/likeknu/service/AnnouncementService.java index 3c67897..6aa7090 100644 --- a/src/main/java/ac/knu/likeknu/service/AnnouncementService.java +++ b/src/main/java/ac/knu/likeknu/service/AnnouncementService.java @@ -65,15 +65,18 @@ public List getAnnouncements(Campus campus, Category c .toList(); } - public List searchAnnouncements(Campus campus, PageDto pageDto, String keyword) { + public List searchAnnouncements(Campus campus, PageDto pageDto, String keyword, String deviceId) { int requestPage = pageDto.getCurrentPage() - 1; PageRequest pageRequest = PageRequest.of(requestPage, DEFAULT_ANNOUNCEMENT_PAGE_SIZE, Sort.by(Order.desc("announcementDate"), Order.desc("collectedAt"))); Slice announcementsPage = announcementRepository .findByCampusInAndAnnouncementTitleContains(Set.of(campus, Campus.ALL), keyword, pageRequest); + + Device device = deviceRepository.findById(deviceId) + .orElseThrow(() -> new BusinessException(String.format("Device not found! [%s]", deviceId))); return announcementsPage.stream() - .map(AnnouncementListResponse::of) + .map(announcement -> AnnouncementListResponse.of(announcement, device.getBookmarks())) .toList(); } }