-
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.
⚡️: fix Answer, Question 관련 오류 수정 #38
- Loading branch information
Showing
10 changed files
with
78 additions
and
97 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
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
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.
32 changes: 24 additions & 8 deletions
32
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,38 @@ | ||
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).orElse(null) | ||
?: throw NotFoundException(ErrorCode.NOT_FOUND_QUESTION_EXCEPTION, "존재하지 않는 질문 $id 입니다") | ||
|
||
fun findQuestionDate(date: LocalDateTime): Question = | ||
questionRepository.findByExposedAtOrNull(date) ?: throw InternalServerException( | ||
ErrorCode.DATA_NOT_READY_EXCEPTION, | ||
"($date) 날짜의 질문데이터가 준비되지 않았습니다. " | ||
) | ||
|
||
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 findQuestionDate(LocalDateTime.now()) | ||
} | ||
|
||
} |
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