use of wooteco.prolog.studylog.application.dto.StudylogDocumentResponse in project prolog by woowacourse.
the class StudylogDocumentService method findBySearchKeyword.
@Override
public StudylogDocumentResponse findBySearchKeyword(String keyword, List<Long> tags, List<Long> missions, List<Long> levels, List<String> usernames, LocalDate start, LocalDate end, Pageable pageable) {
final Query query = StudylogDocumentQueryBuilder.makeQuery(preprocess(keyword), tags, missions, levels, usernames, start, end, pageable);
// Query 결과를 ES에서 조회한다.
final SearchHits<StudylogDocument> searchHits = elasticsearchRestTemplate.search(query, StudylogDocument.class, IndexCoordinates.of("studylog-document"));
// 조회된 SearchHits를 페이징할 수 있는 SearchPage로 변경한다.
final SearchPage<StudylogDocument> searchPages = SearchHitSupport.searchPageFor(searchHits, query.getPageable());
final List<Long> studylogIds = searchPages.stream().map(searchPage -> searchPage.getContent().getId()).collect(toList());
return StudylogDocumentResponse.of(studylogIds, searchPages.getTotalElements(), searchPages.getTotalPages(), searchPages.getNumber());
}
use of wooteco.prolog.studylog.application.dto.StudylogDocumentResponse in project prolog by woowacourse.
the class StudylogService method findStudylogs.
public StudylogsResponse findStudylogs(StudylogsSearchRequest request, Long memberId) {
if (Objects.nonNull(request.getIds())) {
Pageable pageable = request.getPageable();
List<Long> ids = request.getIds();
Page<Studylog> studylogs = studylogRepository.findByIdInAndDeletedFalseOrderByIdAsc(ids, pageable);
return StudylogsResponse.of(studylogs, memberId);
}
if (request.getKeyword() == null || request.getKeyword().isEmpty()) {
return findStudylogsWithoutKeyword(request.getSessions(), request.getMissions(), request.getTags(), request.getUsernames(), request.getMembers(), request.getStartDate(), request.getEndDate(), request.getPageable(), memberId);
}
final StudylogDocumentResponse response = studylogDocumentService.findBySearchKeyword(request.getKeyword(), request.getTags(), request.getMissions(), request.getSessions(), request.getUsernames(), request.getStartDate(), request.getEndDate(), request.getPageable());
final List<Studylog> studylogs = studylogRepository.findByIdInAndDeletedFalseOrderByIdDesc(response.getStudylogIds());
return StudylogsResponse.of(studylogs, response.getTotalSize(), response.getTotalPage(), response.getCurrPage(), memberId);
}
Aggregations