Skip to content

Commit

Permalink
feat: announcement search include device bookmark
Browse files Browse the repository at this point in the history
  • Loading branch information
jcw1031 committed May 5, 2024
1 parent 3142e56 commit 3e05e11
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ public PageResponseDto<List<AnnouncementListResponse>> recentAnnouncementList(
public PageResponseDto<List<AnnouncementListResponse>> 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<AnnouncementListResponse> announcements =
announcementService.searchAnnouncements(campus, pageDto, keyword.trim());
announcementService.searchAnnouncements(campus, pageDto, keyword.trim(), deviceId);
return PageResponseDto.of(announcements, pageDto);
}
}
7 changes: 5 additions & 2 deletions src/main/java/ac/knu/likeknu/service/AnnouncementService.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,18 @@ public List<AnnouncementListResponse> getAnnouncements(Campus campus, Category c
.toList();
}

public List<AnnouncementListResponse> searchAnnouncements(Campus campus, PageDto pageDto, String keyword) {
public List<AnnouncementListResponse> 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<Announcement> 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();
}
}

0 comments on commit 3e05e11

Please sign in to comment.