Skip to content

Commit

Permalink
Merge pull request #194 from dnd-side-project/fix-#193
Browse files Browse the repository at this point in the history
Fix popular words API response by view count-based retrieval
  • Loading branch information
miraexhoi authored Nov 10, 2024
2 parents fa5c2cf + b486b6d commit 0861488
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
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

0 comments on commit 0861488

Please sign in to comment.