Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix popular words API response by view count-based retrieval #194

Merged
merged 2 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public List<WordSearchInfoDto> search(SearchWordConditionInfoDto dto) {
}

public List<PopularWordInfoDto> findPopularAll(Pageable pageable) {
List<Word> result = popularWordRepository.findAllBy(LocalDateTime.now(clock), pageable);
List<Word> result = popularWordRepository.findByViewCount(pageable);

return WordServiceMapper.from(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public interface PopularWordRepository {

List<Word> findAllBy(LocalDateTime target, Pageable pageable);

List<Word> findByViewCount(Pageable pageable);

Optional<PopularWordMetadata> findBy(Long wordId, LocalDateTime target);

Optional<PopularWordSchedule> findBy(LocalDateTime target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ public List<Word> findAllBy(LocalDateTime target, Pageable pageable) {
return result;
}

@Override
public List<Word> findByViewCount(Pageable pageable) {
return queryFactory.selectFrom(word)
.orderBy(word.viewCount.desc())
.limit(pageable.getPageSize())
.fetch();
}

@Override
public Optional<PopularWordMetadata> findBy(Long wordId, LocalDateTime target) {
PopularWordMetadata result = queryFactory.selectFrom(popularWordMetadata)
Expand Down
Loading