Skip to content

Commit

Permalink
Merge pull request #158 from dnd-side-project/feature/#155
Browse files Browse the repository at this point in the history
Add total word count query api
  • Loading branch information
miraexhoi authored Sep 23, 2024
2 parents f734efd + f253fa2 commit 73987e2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public DetailWordInfoDto findBy(String email, Long wordId) {
}
}

public long getTotalWordCount() {
return wordRepository.countAllWords();
}

public List<ListWordInfoDto> findRecentWords() {
List<Word> result = wordRepository.findRecentWords();
return WordServiceMapper.to(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public void delete(Word word) {
wordCrudRepository.delete(word);
}

@Override
public long countAllWords() {
return queryFactory.selectFrom(word)
.fetchCount();
}

@Override
public Optional<Word> findBy(Long wordId) {
Word result = queryFactory.selectFrom(word)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public interface WordRepository {

void delete(Word word);

long countAllWords();

List<Word> findRecentWords();

List<Word> findRandomWords();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ public ResponseEntity<DetailWordInfoResponse> findBy(
return ResponseEntity.ok(WordControllerMapper.to(result));
}

@GetMapping("/count")
public ResponseEntity<Long> getTotalWordCount() {
long totalWordCount = wordService.getTotalWordCount();
return ResponseEntity.ok(totalWordCount);
}

@GetMapping("/candidates")
public ResponseEntity<InputWordCandidateResponse> findCandidateAllBy(String name) {
InputWordCandidateDto result = wordService.findCandidateAllBy(name);
Expand Down

0 comments on commit 73987e2

Please sign in to comment.