-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[FIX] Answer, Question 관련 오류 수정
- Loading branch information
Showing
13 changed files
with
109 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
plu-domain/src/main/kotlin/com/th/plu/domain/domain/answer/AnswerExplorer.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
plu-domain/src/main/kotlin/com/th/plu/domain/domain/question/QuestionExplorer.kt
This file was deleted.
Oops, something went wrong.
48 changes: 41 additions & 7 deletions
48
plu-domain/src/main/kotlin/com/th/plu/domain/domain/question/explorer/QuestionExplorer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,56 @@ | ||
package com.th.plu.domain.domain.answer.explorer | ||
package com.th.plu.domain.domain.question.explorer | ||
|
||
import com.th.plu.common.exception.code.ErrorCode | ||
import com.th.plu.common.exception.model.InternalServerException | ||
import com.th.plu.common.exception.model.NotFoundException | ||
import com.th.plu.domain.domain.question.Question | ||
import com.th.plu.domain.domain.question.repository.QuestionRepository | ||
import org.springframework.stereotype.Component | ||
import java.time.LocalDateTime | ||
import java.time.YearMonth | ||
|
||
@Component | ||
class QuestionExplorer( | ||
private val questionRepository: QuestionRepository | ||
private val questionRepository: QuestionRepository, | ||
) { | ||
fun findQuestionById(id: Long): Question { | ||
return questionRepository.findQuestionById(id) | ||
?: throw NotFoundException(ErrorCode.NOT_FOUND_QUESTION_EXCEPTION, "존재하지 않는 질문(ID: $id) 입니다") | ||
fun findQuestion(id: Long): Question = | ||
questionRepository.findById(id).orElseThrow { | ||
NotFoundException(ErrorCode.NOT_FOUND_QUESTION_EXCEPTION, "존재 하지 않는 질문 $id 입니다") | ||
} | ||
|
||
fun findQuestionByDateTime(dateTime: LocalDateTime): Question { | ||
// 입력된 dateTime이 밤 10시 이후인지 확인 | ||
val isAfterTenPM = dateTime.hour >= 22 | ||
|
||
// 밤 10시 이후인 경우, startOfQuestionPeriod를 그 날의 밤 10시로 설정 | ||
// 그렇지 않으면, startOfQuestionPeriod를 전날의 밤 10시로 설정 | ||
val startOfQuestionPeriod = if (isAfterTenPM) { | ||
dateTime.toLocalDate().atTime(22, 0) | ||
} else { | ||
dateTime.toLocalDate().minusDays(1).atTime(22, 0) | ||
} | ||
|
||
// endOfQuestionPeriod는 startOfQuestionPeriod에서 하루를 더한 후, 밤 9시 59분 59초로 설정 | ||
val endOfQuestionPeriod = startOfQuestionPeriod.plusDays(1).withHour(21).withMinute(59).withSecond(59) | ||
|
||
// 해당 기간 내의 첫 번째 질문을 조회 | ||
return questionRepository.findByExposedAtOrNull(startOfQuestionPeriod, endOfQuestionPeriod) | ||
?: throw InternalServerException( | ||
ErrorCode.DATA_NOT_READY_EXCEPTION, | ||
"($dateTime) 날짜의 질문데이터가 준비되지 않았습니다." | ||
) | ||
} | ||
|
||
fun findMyQuestionsMonthly(memberId: Long, yearMonth: YearMonth): List<Question> = | ||
questionRepository.findAllByExposedMonthIn(memberId, yearMonth) | ||
|
||
fun findAnsweredYearMonth(memberId: Long): Set<YearMonth> = | ||
questionRepository.findAllExposedAtInAnsweredMonth(memberId) | ||
.map { YearMonth.of(it.year, it.monthValue) } | ||
.toSet() // application 에서 중복 처리중, 500 넘는 warn log 발생시 월별 1건 조회하도록 쿼리 개선 필요! | ||
|
||
fun findTodayQuestion(): Question { | ||
return questionRepository.findTodayQuestion() | ||
?: throw NotFoundException(ErrorCode.NOT_FOUND_QUESTION_EXCEPTION, "오늘의 질문이 존재하지 않습니다") | ||
return findQuestionByDateTime(LocalDateTime.now()) | ||
} | ||
|
||
} |
Oops, something went wrong.