Skip to content

Commit

Permalink
Merge pull request #95 from mash-up-kr/xonmin/fix-get-questionSet-query
Browse files Browse the repository at this point in the history
fix : 운영/발행예정 QSet 조회 쿼리 수정
  • Loading branch information
xonmin authored Aug 16, 2024
2 parents f0e8e31 + d90b578 commit e900e82
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
11 changes: 4 additions & 7 deletions entity/src/main/kotlin/com/mashup/dojo/QuestionSetRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@ import org.springframework.data.jpa.repository.JpaRepository
import java.time.LocalDateTime

interface QuestionSetRepository : JpaRepository<QuestionSetEntity, String> {
// publishedYn : True && publishedAt > now -> 현재 운영중인 QuestionSet
fun findByPublishedAtAfterAndEndAtBefore(
// publishedAt < now < endAt -> 현재 운영중인 QuestionSet
fun findByPublishedAtBeforeAndEndAtAfterOrderByPublishedAtAsc(
publishedCompareTime: LocalDateTime = LocalDateTime.now(),
endTimeCompareTime: LocalDateTime = LocalDateTime.now(),
): QuestionSetEntity?

// publishedYn : True && publishedAt < now -> 발행 직전(예정) QuestionSet
fun findByStatusAndPublishedAtAfter(
status: Status,
compareTime: LocalDateTime = LocalDateTime.now(),
): QuestionSetEntity?
// publishedAt > now && 가장 작은 publishedAt -> 발행 직전(예정) QuestionSet
fun findFirstByPublishedAtAfterOrderByPublishedAtAsc(compareTime: LocalDateTime = LocalDateTime.now()): QuestionSetEntity?

fun findTopByOrderByPublishedAtDesc(): QuestionSetEntity?
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class DefaultQuestionService(

// 현재 운영중인 QuestionSet
override fun getOperatingQuestionSet(): QuestionSet? {
return questionSetRepository.findByPublishedAtAfterAndEndAtBefore(LocalDateTime.now(), LocalDateTime.now())
return questionSetRepository.findByPublishedAtBeforeAndEndAtAfterOrderByPublishedAtAsc()
?.toQuestionSet() ?: run {
log.error { "Published And Operating QuestionSet Entity not found" }
null
Expand All @@ -125,8 +125,7 @@ class DefaultQuestionService(

// 발행 출격 준비 완료 QuestionSet
override fun getNextOperatingQuestionSet(): QuestionSet? {
return questionSetRepository.findByStatusAndPublishedAtAfter(Status.UPCOMING, LocalDateTime.now())
?.toQuestionSet() ?: run {
return questionSetRepository.findFirstByPublishedAtAfterOrderByPublishedAtAsc()?.toQuestionSet() ?: run {
log.error { "Published And Prepared for sortie QuestionSet Entity not found" }
null
}
Expand Down

0 comments on commit e900e82

Please sign in to comment.