Skip to content

Commit

Permalink
feature: 퀴즈 조회 api 구현 (#39)
Browse files Browse the repository at this point in the history
* feature: 퀴즈 조회 api 구현.

* feature: 퀴즈 repository 코드 수정
  • Loading branch information
sleepyhoon authored Jul 27, 2024
1 parent e9bba3c commit 6820c2a
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -19,4 +20,10 @@ public ResponseEntity<List<Article>> findArticles(@RequestParam ArticleQueryOpti
List<Article> response = articleService.findArticles(queryOption);
return ResponseEntity.ok(response);
}

@GetMapping("/quizzes/{articleId}")
public ResponseEntity<List<Quiz>> findQuizzes(@PathVariable Long articleId, @RequestBody String nickname) {
List<Quiz> response = articleService.findQuizzes(articleId);
return ResponseEntity.ok(response);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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) {}
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Quiz> searchQuiz(Long articleId);
}
Original file line number Diff line number Diff line change
@@ -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<Quiz> searchQuiz(Long articleId) {
return queryFactory
.selectFrom(quiz)
.where(quiz.article.id.eq(articleId))
.fetch();
}
}
Original file line number Diff line number Diff line change
@@ -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<Quiz, Long>, QuizCustomRepository {}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,8 +16,13 @@
public class ArticleService {

private final ArticleRepository articleRepository;
private final QuizRepository quizRepository;

public List<Article> findArticles(ArticleQueryOption queryOption) {
return articleRepository.searchArticle(queryOption);
}

public List<Quiz> findQuizzes(Long articleId) {
return quizRepository.searchQuiz(articleId);
}
}

0 comments on commit 6820c2a

Please sign in to comment.