From d126ac5ad760f4ea34df5df6c1ea1a0d3eb50b2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EB=AF=B8=EB=9E=98?= Date: Mon, 23 Sep 2024 11:03:31 +0900 Subject: [PATCH 1/3] feature :: add count all words query --- .../word/domain/repository/QuerydslWordRepository.java | 6 ++++++ .../domain/word/domain/repository/WordRepository.java | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/main/java/com/dnd/spaced/domain/word/domain/repository/QuerydslWordRepository.java b/src/main/java/com/dnd/spaced/domain/word/domain/repository/QuerydslWordRepository.java index c607068..cc3d932 100644 --- a/src/main/java/com/dnd/spaced/domain/word/domain/repository/QuerydslWordRepository.java +++ b/src/main/java/com/dnd/spaced/domain/word/domain/repository/QuerydslWordRepository.java @@ -46,6 +46,12 @@ public void delete(Word word) { wordCrudRepository.delete(word); } + @Override + public long countAllWords() { + return queryFactory.selectFrom(word) + .fetchCount(); + } + @Override public Optional findBy(Long wordId) { Word result = queryFactory.selectFrom(word) diff --git a/src/main/java/com/dnd/spaced/domain/word/domain/repository/WordRepository.java b/src/main/java/com/dnd/spaced/domain/word/domain/repository/WordRepository.java index c335102..b3b3ec1 100644 --- a/src/main/java/com/dnd/spaced/domain/word/domain/repository/WordRepository.java +++ b/src/main/java/com/dnd/spaced/domain/word/domain/repository/WordRepository.java @@ -14,6 +14,8 @@ public interface WordRepository { void delete(Word word); + long countAllWords(); + List findRecentWords(); List findRandomWords(); From 2cc074ad88ecc955771f64fa405f41cdbe0fea37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EB=AF=B8=EB=9E=98?= Date: Mon, 23 Sep 2024 11:03:46 +0900 Subject: [PATCH 2/3] feature :: add getTotalWordCount word service logic --- .../com/dnd/spaced/domain/word/application/WordService.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/dnd/spaced/domain/word/application/WordService.java b/src/main/java/com/dnd/spaced/domain/word/application/WordService.java index 5f314d3..6a2acba 100644 --- a/src/main/java/com/dnd/spaced/domain/word/application/WordService.java +++ b/src/main/java/com/dnd/spaced/domain/word/application/WordService.java @@ -61,6 +61,10 @@ public DetailWordInfoDto findBy(String email, Long wordId) { } } + public long getTotalWordCount() { + return wordRepository.countAllWords(); + } + public List findRecentWords() { List result = wordRepository.findRecentWords(); return WordServiceMapper.to(result); From f253fa2119e73ee74a9ca815239a56c74141460b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EB=AF=B8=EB=9E=98?= Date: Mon, 23 Sep 2024 11:03:58 +0900 Subject: [PATCH 3/3] feature :: add /words/count api --- .../dnd/spaced/domain/word/presentation/WordController.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/dnd/spaced/domain/word/presentation/WordController.java b/src/main/java/com/dnd/spaced/domain/word/presentation/WordController.java index a97d4f8..21eafbe 100644 --- a/src/main/java/com/dnd/spaced/domain/word/presentation/WordController.java +++ b/src/main/java/com/dnd/spaced/domain/word/presentation/WordController.java @@ -58,6 +58,12 @@ public ResponseEntity findBy( return ResponseEntity.ok(WordControllerMapper.to(result)); } + @GetMapping("/count") + public ResponseEntity getTotalWordCount() { + long totalWordCount = wordService.getTotalWordCount(); + return ResponseEntity.ok(totalWordCount); + } + @GetMapping("/candidates") public ResponseEntity findCandidateAllBy(String name) { InputWordCandidateDto result = wordService.findCandidateAllBy(name);