From 6820c2a91c3ab4f248979b5eec0f7e8e6b54a784 Mon Sep 17 00:00:00 2001 From: SeungHoon Han <101882530+sleepyhoon@users.noreply.github.com> Date: Sun, 28 Jul 2024 02:54:14 +0900 Subject: [PATCH] =?UTF-8?q?feature:=20=ED=80=B4=EC=A6=88=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20api=20=EA=B5=AC=ED=98=84=20(#39)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feature: 퀴즈 조회 api 구현. * feature: 퀴즈 repository 코드 수정 --- .../article/controller/ArticleController.java | 9 +++++++- .../article/domain/ArticleQueryOption.java | 3 --- .../dto/request/ArticleQueryOption.java | 6 +++++ .../ArticleCustomRepository.java | 5 ++--- .../ArticleCustomRepositoryImpl.java | 5 +++-- .../{ => article}/ArticleRepository.java | 2 +- .../repository/quiz/QuizCustomRepository.java | 8 +++++++ .../quiz/QuizCustomRepositoryImpl.java | 22 +++++++++++++++++++ .../repository/quiz/QuizRepository.java | 6 +++++ .../article/service/ArticleService.java | 11 ++++++++-- 10 files changed, 65 insertions(+), 12 deletions(-) delete mode 100644 src/main/java/com/goldbalance/dive/domain/article/domain/ArticleQueryOption.java create mode 100644 src/main/java/com/goldbalance/dive/domain/article/dto/request/ArticleQueryOption.java rename src/main/java/com/goldbalance/dive/domain/article/repository/{ => article}/ArticleCustomRepository.java (52%) rename src/main/java/com/goldbalance/dive/domain/article/repository/{ => article}/ArticleCustomRepositoryImpl.java (81%) rename src/main/java/com/goldbalance/dive/domain/article/repository/{ => article}/ArticleRepository.java (77%) create mode 100644 src/main/java/com/goldbalance/dive/domain/article/repository/quiz/QuizCustomRepository.java create mode 100644 src/main/java/com/goldbalance/dive/domain/article/repository/quiz/QuizCustomRepositoryImpl.java create mode 100644 src/main/java/com/goldbalance/dive/domain/article/repository/quiz/QuizRepository.java diff --git a/src/main/java/com/goldbalance/dive/domain/article/controller/ArticleController.java b/src/main/java/com/goldbalance/dive/domain/article/controller/ArticleController.java index 96f2502..adda9e8 100644 --- a/src/main/java/com/goldbalance/dive/domain/article/controller/ArticleController.java +++ b/src/main/java/com/goldbalance/dive/domain/article/controller/ArticleController.java @@ -1,7 +1,8 @@ package com.goldbalance.dive.domain.article.controller; import com.goldbalance.dive.domain.article.domain.Article; -import com.goldbalance.dive.domain.article.domain.ArticleQueryOption; +import com.goldbalance.dive.domain.article.domain.Quiz; +import com.goldbalance.dive.domain.article.dto.request.ArticleQueryOption; import com.goldbalance.dive.domain.article.service.ArticleService; import java.util.List; import lombok.RequiredArgsConstructor; @@ -19,4 +20,10 @@ public ResponseEntity> findArticles(@RequestParam ArticleQueryOpti List
response = articleService.findArticles(queryOption); return ResponseEntity.ok(response); } + + @GetMapping("/quizzes/{articleId}") + public ResponseEntity> findQuizzes(@PathVariable Long articleId, @RequestBody String nickname) { + List response = articleService.findQuizzes(articleId); + return ResponseEntity.ok(response); + } } diff --git a/src/main/java/com/goldbalance/dive/domain/article/domain/ArticleQueryOption.java b/src/main/java/com/goldbalance/dive/domain/article/domain/ArticleQueryOption.java deleted file mode 100644 index 0dfe0e9..0000000 --- a/src/main/java/com/goldbalance/dive/domain/article/domain/ArticleQueryOption.java +++ /dev/null @@ -1,3 +0,0 @@ -package com.goldbalance.dive.domain.article.domain; - -public record ArticleQueryOption(String keyword, Category category, Duration duration) {} diff --git a/src/main/java/com/goldbalance/dive/domain/article/dto/request/ArticleQueryOption.java b/src/main/java/com/goldbalance/dive/domain/article/dto/request/ArticleQueryOption.java new file mode 100644 index 0000000..f8ee75b --- /dev/null +++ b/src/main/java/com/goldbalance/dive/domain/article/dto/request/ArticleQueryOption.java @@ -0,0 +1,6 @@ +package com.goldbalance.dive.domain.article.dto.request; + +import com.goldbalance.dive.domain.article.domain.Category; +import com.goldbalance.dive.domain.article.domain.Duration; + +public record ArticleQueryOption(String keyword, Category category, Duration duration) {} diff --git a/src/main/java/com/goldbalance/dive/domain/article/repository/ArticleCustomRepository.java b/src/main/java/com/goldbalance/dive/domain/article/repository/article/ArticleCustomRepository.java similarity index 52% rename from src/main/java/com/goldbalance/dive/domain/article/repository/ArticleCustomRepository.java rename to src/main/java/com/goldbalance/dive/domain/article/repository/article/ArticleCustomRepository.java index 570e190..2046628 100644 --- a/src/main/java/com/goldbalance/dive/domain/article/repository/ArticleCustomRepository.java +++ b/src/main/java/com/goldbalance/dive/domain/article/repository/article/ArticleCustomRepository.java @@ -1,8 +1,7 @@ -package com.goldbalance.dive.domain.article.repository; +package com.goldbalance.dive.domain.article.repository.article; import com.goldbalance.dive.domain.article.domain.Article; -import com.goldbalance.dive.domain.article.domain.ArticleQueryOption; -import com.querydsl.core.types.dsl.BooleanExpression; +import com.goldbalance.dive.domain.article.dto.request.ArticleQueryOption; import java.util.List; public interface ArticleCustomRepository { diff --git a/src/main/java/com/goldbalance/dive/domain/article/repository/ArticleCustomRepositoryImpl.java b/src/main/java/com/goldbalance/dive/domain/article/repository/article/ArticleCustomRepositoryImpl.java similarity index 81% rename from src/main/java/com/goldbalance/dive/domain/article/repository/ArticleCustomRepositoryImpl.java rename to src/main/java/com/goldbalance/dive/domain/article/repository/article/ArticleCustomRepositoryImpl.java index e19f44e..1032964 100644 --- a/src/main/java/com/goldbalance/dive/domain/article/repository/ArticleCustomRepositoryImpl.java +++ b/src/main/java/com/goldbalance/dive/domain/article/repository/article/ArticleCustomRepositoryImpl.java @@ -1,9 +1,10 @@ -package com.goldbalance.dive.domain.article.repository; +package com.goldbalance.dive.domain.article.repository.article; import static com.goldbalance.dive.domain.article.domain.QArticle.*; +import static com.goldbalance.dive.domain.article.domain.QQuiz.*; import com.goldbalance.dive.domain.article.domain.Article; -import com.goldbalance.dive.domain.article.domain.ArticleQueryOption; +import com.goldbalance.dive.domain.article.dto.request.ArticleQueryOption; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; import java.util.List; diff --git a/src/main/java/com/goldbalance/dive/domain/article/repository/ArticleRepository.java b/src/main/java/com/goldbalance/dive/domain/article/repository/article/ArticleRepository.java similarity index 77% rename from src/main/java/com/goldbalance/dive/domain/article/repository/ArticleRepository.java rename to src/main/java/com/goldbalance/dive/domain/article/repository/article/ArticleRepository.java index 1ae7af7..49d27c5 100644 --- a/src/main/java/com/goldbalance/dive/domain/article/repository/ArticleRepository.java +++ b/src/main/java/com/goldbalance/dive/domain/article/repository/article/ArticleRepository.java @@ -1,4 +1,4 @@ -package com.goldbalance.dive.domain.article.repository; +package com.goldbalance.dive.domain.article.repository.article; import com.goldbalance.dive.domain.article.domain.Article; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/src/main/java/com/goldbalance/dive/domain/article/repository/quiz/QuizCustomRepository.java b/src/main/java/com/goldbalance/dive/domain/article/repository/quiz/QuizCustomRepository.java new file mode 100644 index 0000000..ccb0b83 --- /dev/null +++ b/src/main/java/com/goldbalance/dive/domain/article/repository/quiz/QuizCustomRepository.java @@ -0,0 +1,8 @@ +package com.goldbalance.dive.domain.article.repository.quiz; + +import com.goldbalance.dive.domain.article.domain.Quiz; +import java.util.List; + +public interface QuizCustomRepository { + List searchQuiz(Long articleId); +} diff --git a/src/main/java/com/goldbalance/dive/domain/article/repository/quiz/QuizCustomRepositoryImpl.java b/src/main/java/com/goldbalance/dive/domain/article/repository/quiz/QuizCustomRepositoryImpl.java new file mode 100644 index 0000000..c1f364a --- /dev/null +++ b/src/main/java/com/goldbalance/dive/domain/article/repository/quiz/QuizCustomRepositoryImpl.java @@ -0,0 +1,22 @@ +package com.goldbalance.dive.domain.article.repository.quiz; + +import static com.goldbalance.dive.domain.article.domain.QQuiz.quiz; + +import com.goldbalance.dive.domain.article.domain.Quiz; +import com.querydsl.jpa.impl.JPAQueryFactory; +import java.util.List; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class QuizCustomRepositoryImpl implements QuizCustomRepository { + + private final JPAQueryFactory queryFactory; + + @Override + public List searchQuiz(Long articleId) { + return queryFactory + .selectFrom(quiz) + .where(quiz.article.id.eq(articleId)) + .fetch(); + } +} diff --git a/src/main/java/com/goldbalance/dive/domain/article/repository/quiz/QuizRepository.java b/src/main/java/com/goldbalance/dive/domain/article/repository/quiz/QuizRepository.java new file mode 100644 index 0000000..ec48f60 --- /dev/null +++ b/src/main/java/com/goldbalance/dive/domain/article/repository/quiz/QuizRepository.java @@ -0,0 +1,6 @@ +package com.goldbalance.dive.domain.article.repository.quiz; + +import com.goldbalance.dive.domain.article.domain.Quiz; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface QuizRepository extends JpaRepository, QuizCustomRepository {} diff --git a/src/main/java/com/goldbalance/dive/domain/article/service/ArticleService.java b/src/main/java/com/goldbalance/dive/domain/article/service/ArticleService.java index 372ac71..c975d27 100644 --- a/src/main/java/com/goldbalance/dive/domain/article/service/ArticleService.java +++ b/src/main/java/com/goldbalance/dive/domain/article/service/ArticleService.java @@ -1,8 +1,10 @@ package com.goldbalance.dive.domain.article.service; import com.goldbalance.dive.domain.article.domain.Article; -import com.goldbalance.dive.domain.article.domain.ArticleQueryOption; -import com.goldbalance.dive.domain.article.repository.ArticleRepository; +import com.goldbalance.dive.domain.article.domain.Quiz; +import com.goldbalance.dive.domain.article.dto.request.ArticleQueryOption; +import com.goldbalance.dive.domain.article.repository.article.ArticleRepository; +import com.goldbalance.dive.domain.article.repository.quiz.QuizRepository; import jakarta.transaction.Transactional; import java.util.List; import lombok.RequiredArgsConstructor; @@ -14,8 +16,13 @@ public class ArticleService { private final ArticleRepository articleRepository; + private final QuizRepository quizRepository; public List
findArticles(ArticleQueryOption queryOption) { return articleRepository.searchArticle(queryOption); } + + public List findQuizzes(Long articleId) { + return quizRepository.searchQuiz(articleId); + } }