diff --git a/plu-api/src/main/kotlin/com/th/plu/api/service/answer/AnswerService.kt b/plu-api/src/main/kotlin/com/th/plu/api/service/answer/AnswerService.kt index 8342712..8bcb03c 100644 --- a/plu-api/src/main/kotlin/com/th/plu/api/service/answer/AnswerService.kt +++ b/plu-api/src/main/kotlin/com/th/plu/api/service/answer/AnswerService.kt @@ -77,6 +77,7 @@ class AnswerService( return EveryAnswerInfoResponse.of(todayQuestion, answerCount) } + @Transactional(readOnly = true) fun findAllAnswersLikeTopN(getCount: Long): EveryAnswerRetrieveResponses { val todayQuestion = questionExplorer.findTodayQuestion() val answers = answerRepository.findPublicAnswersLikeTopN(todayQuestion.id, getCount) @@ -92,16 +93,7 @@ class AnswerService( return try { answerRegister.registerAnswer(memberEntity, questionEntity, answerWriting.body, answerWriting.open).let { - WritingAnswerResult( - questionId = questionEntity.id, - questionTitle = questionEntity.title, - questionContent = questionEntity.content, - questionExposedAt = questionEntity.exposedAt, - questionElementType = questionEntity.elementType, - questionAnswered = true, - answerId = it.id, - answerBody = it.content, - reactionLikeCount = 0 // 최초 생성시는 0 + WritingAnswerResult(questionId = questionEntity.id, questionTitle = questionEntity.title, questionContent = questionEntity.content, questionExposedAt = questionEntity.exposedAt, questionElementType = questionEntity.elementType, questionAnswered = true, answerId = it.id, answerBody = it.content, reactionLikeCount = 0 // 최초 생성시는 0 ) } } catch (e: DataIntegrityViolationException) { diff --git a/plu-domain/src/main/kotlin/com/th/plu/domain/domain/question/explorer/QuestionExplorer.kt b/plu-domain/src/main/kotlin/com/th/plu/domain/domain/question/explorer/QuestionExplorer.kt index 94c18af..f0e59dc 100644 --- a/plu-domain/src/main/kotlin/com/th/plu/domain/domain/question/explorer/QuestionExplorer.kt +++ b/plu-domain/src/main/kotlin/com/th/plu/domain/domain/question/explorer/QuestionExplorer.kt @@ -14,8 +14,9 @@ class QuestionExplorer( private val questionRepository: QuestionRepository, ) { fun findQuestion(id: Long): Question = - questionRepository.findById(id).orElse(null) - ?: throw NotFoundException(ErrorCode.NOT_FOUND_QUESTION_EXCEPTION, "존재하지 않는 질문 $id 입니다") + questionRepository.findById(id).orElseThrow { + NotFoundException(ErrorCode.NOT_FOUND_QUESTION_EXCEPTION, "존재 하지 않는 질문 $id 입니다") + } fun findQuestionByDateTime(dateTime: LocalDateTime): Question { // 입력된 dateTime이 밤 10시 이후인지 확인