-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 특정 플레이어의 퀴즈 목록 조회 #65
The head ref may contain hidden characters: "feat/#63-\uD50C\uB808\uC774\uC5B4\uAC00\uC0DD\uC131\uD55C\uD034\uC988\uBAA9\uB85D\uC870\uD68C"
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package yjh.cstar.quiz.application.port.QuizFilter | ||
|
||
import org.springframework.data.domain.Page | ||
import org.springframework.data.domain.Pageable | ||
import yjh.cstar.quiz.application.port.QuizRepository | ||
import yjh.cstar.quiz.domain.Quiz | ||
|
||
class AttemptedQuizFilter( | ||
private val quizRepository: QuizRepository, | ||
) : QuizFilter { | ||
override fun filter(memberId: Long, pageable: Pageable): Page<Quiz> { | ||
return quizRepository.findAllAttemptedByMember(memberId, pageable) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package yjh.cstar.quiz.application.port.QuizFilter | ||
|
||
import org.springframework.data.domain.Page | ||
import org.springframework.data.domain.Pageable | ||
import yjh.cstar.quiz.application.port.QuizRepository | ||
import yjh.cstar.quiz.domain.Quiz | ||
|
||
class CreatedQuizFilter( | ||
private val quizRepository: QuizRepository, | ||
) : QuizFilter { | ||
override fun filter(writerId: Long, pageable: Pageable): Page<Quiz> { | ||
return quizRepository.findAllCreatedByMember(writerId, pageable) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package yjh.cstar.quiz.application.port.QuizFilter | ||
|
||
import org.springframework.data.domain.Page | ||
import org.springframework.data.domain.Pageable | ||
import yjh.cstar.quiz.domain.Quiz | ||
|
||
interface QuizFilter { | ||
fun filter(memberId: Long, pageable: Pageable): Page<Quiz> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package yjh.cstar.quiz.application.port.QuizFilter | ||
|
||
import org.springframework.stereotype.Component | ||
import yjh.cstar.common.BaseErrorCode | ||
import yjh.cstar.common.BaseException | ||
import yjh.cstar.quiz.application.port.QuizRepository | ||
import yjh.cstar.quiz.domain.QuizFilterType | ||
|
||
@Component | ||
class QuizFilterFactory( | ||
private val quizRepository: QuizRepository, | ||
) { | ||
fun filterType(quizFilterType: String): QuizFilter { | ||
return when (QuizFilterType.create(quizFilterType)) { | ||
QuizFilterType.CREATED -> CreatedQuizFilter(quizRepository) | ||
QuizFilterType.ATTEMPTED -> AttemptedQuizFilter(quizRepository) | ||
else -> throw BaseException(BaseErrorCode.QUIZ_FILTER_INVALID) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package yjh.cstar.quiz.domain | ||
|
||
import yjh.cstar.common.BaseErrorCode | ||
import yjh.cstar.common.BaseException | ||
|
||
enum class QuizFilterType(val description: String) { | ||
CREATED("created"), | ||
ATTEMPTED("attempted"), | ||
CORRECT("correct"), | ||
; | ||
|
||
companion object { | ||
fun create(quizFilter: String): QuizFilterType = | ||
entries.firstOrNull { it.description == quizFilter } | ||
?: throw BaseException(BaseErrorCode.QUIZ_FILTER_INVALID) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,27 @@ interface QuizJpaRepository : JpaRepository<QuizEntity, Long> { | |
|
||
@Query("SELECT q FROM QuizEntity q WHERE q.deletedAt IS NULL AND q.category = :category") | ||
fun findAllByCategory(@Param("category") category: Category, pageable: Pageable): Page<QuizEntity> | ||
|
||
@Query("SELECT q FROM QuizEntity q WHERE q.deletedAt IS NULL AND q.writerId = :memberId") | ||
fun findAllCreatedByMember(@Param("memberId") writerId: Long, pageable: Pageable): Page<QuizEntity> | ||
Comment on lines
+30
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @query문을 아래 처럼 보기좋게 정렬하면 좋을 것 같아요!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네 보기좋게 정렬해보겠습니다!😀 |
||
|
||
@Query( | ||
value = """ | ||
SELECT q.* | ||
FROM quiz q | ||
WHERE q.deleted_at IS NULL | ||
AND q.quiz_id IN ( | ||
SELECT gq.quiz_id | ||
FROM game_quiz gq | ||
JOIN member_game_result mgr ON mgr.game_id = gq.game_id | ||
WHERE mgr.member_id = :memberId | ||
AND mgr.total_count > 0 | ||
Comment on lines
+35
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 해당 쿼리는 여태까지 시도해봤던 모든 퀴즈 기록들을 조회하는 것인가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네 맞습니다. 특정 멤버가 시도한 퀴즈 전체를 조회합니다. 조회 쿼리 같은 경우 어떤 테이블을 조합해서 어떤 데이터를 구체적으로 가져오는지 앞으로는 더 명확하게 적도록 하겠습니다. 😂 |
||
) | ||
""", | ||
nativeQuery = true | ||
) | ||
fun findAllAttemptedByMember( | ||
@Param("memberId") memberId: Long, | ||
pageable: Pageable, | ||
): Page<QuizEntity> | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
코틀린 when 문법으로 깔끔하게 작성하신게 인상깊네요!!
나중에 여러 종류의 필터타입등이 많이 추가될 수 도 있을 것 같은데, 이런 동적으로 받을 수 있는 쿼리스프링 타입에 대해서 어떻게 조회해야될지 고민해보면 좋을 것 같습니다!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네! 다음 조회 기능을 구현할 때 같이 논의해보면 좋을 것 같습니다!😆