diff --git a/plu-api/src/main/kotlin/com/th/plu/api/controller/answer/AnswerController.kt b/plu-api/src/main/kotlin/com/th/plu/api/controller/answer/AnswerController.kt index 622ed96..fa2d8fe 100644 --- a/plu-api/src/main/kotlin/com/th/plu/api/controller/answer/AnswerController.kt +++ b/plu-api/src/main/kotlin/com/th/plu/api/controller/answer/AnswerController.kt @@ -8,8 +8,8 @@ import com.th.plu.api.controller.answer.dto.response.AnswerInfoResponse import com.th.plu.api.controller.answer.dto.response.EveryAnswerInfoResponse import com.th.plu.api.controller.answer.dto.toAnswerWriting import com.th.plu.api.controller.answer.dto.toWritingAnswerResponse -import com.th.plu.common.dto.response.ApiResponse import com.th.plu.api.service.answer.AnswerService +import com.th.plu.common.dto.response.ApiResponse import com.th.plu.domain.domain.answer.dto.EveryAnswerRetrieveResponses import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag @@ -62,7 +62,7 @@ class AnswerController( @GetMapping("/v1/answers/info") fun findEveryAnswerInfo( ): ApiResponse { - return ApiResponse.success(answerService.findEveryAnswerInfo()) + return ApiResponse.success(answerService.findAllAnswerInfo()) } @Auth @@ -72,7 +72,7 @@ class AnswerController( @RequestParam(defaultValue = Long.MAX_VALUE.toString()) lastAnswerId: Long, @RequestParam(defaultValue = "10") pageSize: Long, ): ApiResponse { - return ApiResponse.success(answerService.findEveryAnswersWithCursor(lastAnswerId, pageSize)) + return ApiResponse.success(answerService.findAllAnswersWithCursor(lastAnswerId, pageSize)) } @Auth @@ -81,6 +81,6 @@ class AnswerController( fun getAnswersAboutLikeTopN( @RequestParam(defaultValue = "10") getCount: Long, ): ApiResponse { - return ApiResponse.success(answerService.findEveryAnswersLikeTopN(getCount)) + return ApiResponse.success(answerService.findAllAnswersLikeTopN(getCount)) } } \ No newline at end of file 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 2fc5be1..9efb389 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 @@ -5,6 +5,7 @@ import com.th.plu.api.controller.answer.dto.response.EveryAnswerInfoResponse import com.th.plu.api.service.like.LikeValidator import com.th.plu.common.exception.code.ErrorCode import com.th.plu.common.exception.model.ConflictException +import com.th.plu.common.exception.model.IllegalArgumentException import com.th.plu.domain.domain.answer.AnswerRegister import com.th.plu.domain.domain.answer.AnswerWriting import com.th.plu.domain.domain.answer.WritingAnswerResult @@ -15,7 +16,7 @@ import com.th.plu.domain.domain.like.Like import com.th.plu.domain.domain.like.explorer.LikeExplorer import com.th.plu.domain.domain.like.repository.LikeRepository import com.th.plu.domain.domain.member.explorer.MemberExplorer -import com.th.plu.domain.domain.question.QuestionExplorer +import com.th.plu.domain.domain.question.explorer.QuestionExplorer import com.th.plu.domain.isUniqueError import org.springframework.dao.DataIntegrityViolationException import org.springframework.stereotype.Service @@ -63,21 +64,23 @@ class AnswerService( } @Transactional(readOnly = true) - fun findEveryAnswersWithCursor(lastAnswerId: Long, pageSize: Long): EveryAnswerRetrieveResponses { + fun findAllAnswersWithCursor(lastAnswerId: Long, pageSize: Long): EveryAnswerRetrieveResponses { val todayQuestionId = questionExplorer.findTodayQuestion().id val answers = answerRepository.findEveryAnswersWithCursorAndPageSize(todayQuestionId, lastAnswerId, pageSize) return EveryAnswerRetrieveResponses(answers) } @Transactional(readOnly = true) - fun findEveryAnswerInfo(): EveryAnswerInfoResponse { + fun findAllAnswerInfo(): EveryAnswerInfoResponse { val todayQuestion = questionExplorer.findTodayQuestion() val answerCount = answerRepository.findPublicAnswersCountByQuestionId(todayQuestion.id) + ?: throw IllegalArgumentException(ErrorCode.Illegal_ARGUMENT_ANSWER_COUNT_EXCEPTION, "answerCount는 비어 있을 수 없습니다.") return EveryAnswerInfoResponse.of(todayQuestion, answerCount) } - fun findEveryAnswersLikeTopN(getCount: Long): EveryAnswerRetrieveResponses { + @Transactional(readOnly = true) + fun findAllAnswersLikeTopN(getCount: Long): EveryAnswerRetrieveResponses { val todayQuestion = questionExplorer.findTodayQuestion() val answers = answerRepository.findPublicAnswersLikeTopN(todayQuestion.id, getCount) @@ -92,16 +95,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-api/src/main/kotlin/com/th/plu/api/service/question/QuestionService.kt b/plu-api/src/main/kotlin/com/th/plu/api/service/question/QuestionService.kt index 869b321..7c124ef 100644 --- a/plu-api/src/main/kotlin/com/th/plu/api/service/question/QuestionService.kt +++ b/plu-api/src/main/kotlin/com/th/plu/api/service/question/QuestionService.kt @@ -1,8 +1,8 @@ package com.th.plu.api.service.question -import com.th.plu.domain.domain.answer.AnswerExplorer -import com.th.plu.domain.domain.question.QuestionExplorer +import com.th.plu.domain.domain.answer.explorer.AnswerExplorer import com.th.plu.domain.domain.question.QuestionResultDto +import com.th.plu.domain.domain.question.explorer.QuestionExplorer import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import java.time.LocalDateTime @@ -17,7 +17,7 @@ class QuestionService( fun getQuestionToday(memberId: Long): QuestionResultDto { val today = LocalDateTime.now() - return questionExplorer.findQuestion(today).let { todayQuestion -> + return questionExplorer.findQuestionByDateTime(today).let { todayQuestion -> val answered = answerExplorer.hasAnswered(memberId, todayQuestion.id) QuestionResultDto( diff --git a/plu-common/src/main/kotlin/com/th/plu/common/exception/code/ErrorCode.kt b/plu-common/src/main/kotlin/com/th/plu/common/exception/code/ErrorCode.kt index 0a22e92..767d884 100644 --- a/plu-common/src/main/kotlin/com/th/plu/common/exception/code/ErrorCode.kt +++ b/plu-common/src/main/kotlin/com/th/plu/common/exception/code/ErrorCode.kt @@ -25,18 +25,13 @@ enum class ErrorCode(val code: String, val message: String) { NOT_FOUND_ANSWER_EXCEPTION("N003", "존재하지 않는 답변입니다."), NOT_FOUND_QUESTION_EXCEPTION("N004", "존재하지 않는 질문입니다."), NOT_FOUND_LIKE_EXCEPTION("N005", "존재하지 않는 공감 정보입니다."), - NOT_FOUND_ARTICLE_CONTENT_EXCEPTION("N003", "아티클의 컨텐츠가 존재하지 않습니다."), - NOT_FOUND_CHALLENGE_EXCEPTION("N004", "존재하지 않는 챌린지입니다."), - NOT_FOUND_ARTICLE_EXCEPTION("N005", "삭제되었거나 존재하지 않는 아티클입니다."), - NOT_FOUND_ARTICLE_IN_WEEK_AND_DAY_EXCEPTION("N006", "해당 주차 일차에 해당하는 아티클이 존재하지 않습니다."), - NOT_FOUND_ENDPOINT_EXCEPTION("N007", "존재하지 않는 엔드포인트입니다."), - NOT_FOUND_ONBOARDING_EXCEPTION("N008", "존재하지 않는 엔드포인트입니다."), + NOT_FOUND_ENDPOINT_EXCEPTION("N006", "존재하지 않는 엔드포인트입니다."), + NOT_FOUND_ONBOARDING_EXCEPTION("N007", "존재하지 않는 엔드포인트입니다."), // Conflict Exception CONFLICT_EXCEPTION("C001", "이미 존재합니다."), CONFLICT_MEMBER_EXCEPTION("C002", "이미 해당 계정으로 회원가입하셨습니다.\n로그인 해주세요."), CONFLICT_LIKE_EXCEPTION("C003", "이미 해당 답변에 대한 공감이 되어있습니다."), - CONFLICT_BOOKMARK_EXCEPTION("C003", "요청과 동일한 북마크 상태 입니다."), CONFLICT_NICKNAME_EXCEPTION("C004", "이미 사용 중인 닉네임 입니다."), CONFLICT_ANSWER_EXCEPTION("C005", "이미 존재한 답변이 있습니다."), @@ -49,4 +44,5 @@ enum class ErrorCode(val code: String, val message: String) { // Illegal Argument Exception Illegal_ARGUMENT_NICKNAME_EXCEPTION("IA001", "잘못된 닉네임 형식입니다."), + Illegal_ARGUMENT_ANSWER_COUNT_EXCEPTION("IA002", "answerCount는 비어있을 수 없습니다."), } diff --git a/plu-domain/src/main/kotlin/com/th/plu/domain/domain/answer/Answer.kt b/plu-domain/src/main/kotlin/com/th/plu/domain/domain/answer/Answer.kt index 1ced913..a5f79b4 100644 --- a/plu-domain/src/main/kotlin/com/th/plu/domain/domain/answer/Answer.kt +++ b/plu-domain/src/main/kotlin/com/th/plu/domain/domain/answer/Answer.kt @@ -28,8 +28,7 @@ class Answer( private var _id: Long? = null, @ManyToOne(fetch = FetchType.LAZY, cascade = [CascadeType.ALL]) - @JoinColumn(name = "member_id", nullable = false) - private var member: Member, + @JoinColumn(name = "member_id", nullable = false) var member: Member, @ManyToOne(fetch = FetchType.LAZY, cascade = [CascadeType.ALL]) @JoinColumn(name = "question_id", nullable = false) @@ -53,6 +52,10 @@ class Answer( private set val questionId: Long = question.id + + fun getLikeCount(): Int { + return likes.size + } } fun newAnswerInstance(member: Member, question: Question, content: String, isPublic: Boolean) = Answer( diff --git a/plu-domain/src/main/kotlin/com/th/plu/domain/domain/answer/AnswerExplorer.kt b/plu-domain/src/main/kotlin/com/th/plu/domain/domain/answer/AnswerExplorer.kt deleted file mode 100644 index fd912ba..0000000 --- a/plu-domain/src/main/kotlin/com/th/plu/domain/domain/answer/AnswerExplorer.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.th.plu.domain.domain.answer - -import com.th.plu.domain.domain.answer.repository.AnswerRepository -import org.springframework.stereotype.Component - -@Component -class AnswerExplorer( - private val answerRepository: AnswerRepository, -) { - fun hasAnswered(memberId: Long, questionId: Long): Boolean { - return answerRepository.existsByMemberIdAndQuestionId(memberId, questionId) - } -} \ No newline at end of file diff --git a/plu-domain/src/main/kotlin/com/th/plu/domain/domain/answer/explorer/AnswerExplorer.kt b/plu-domain/src/main/kotlin/com/th/plu/domain/domain/answer/explorer/AnswerExplorer.kt index ac48469..d5fb81a 100644 --- a/plu-domain/src/main/kotlin/com/th/plu/domain/domain/answer/explorer/AnswerExplorer.kt +++ b/plu-domain/src/main/kotlin/com/th/plu/domain/domain/answer/explorer/AnswerExplorer.kt @@ -8,10 +8,14 @@ import org.springframework.stereotype.Component @Component class AnswerExplorer( - private val answerRepository: AnswerRepository + private val answerRepository: AnswerRepository ) { fun findAnswerById(id: Long): Answer { return answerRepository.findAnswerById(id) - ?: throw NotFoundException(ErrorCode.NOT_FOUND_ANSWER_EXCEPTION, "존재하지 않는 답변(ID: $id) 입니다") + ?: throw NotFoundException(ErrorCode.NOT_FOUND_ANSWER_EXCEPTION, "존재하지 않는 답변(ID: $id) 입니다") + } + + fun hasAnswered(memberId: Long, questionId: Long): Boolean { + return answerRepository.existsByMemberIdAndQuestionId(memberId, questionId) } } \ No newline at end of file diff --git a/plu-domain/src/main/kotlin/com/th/plu/domain/domain/answer/repository/AnswerRepositoryCustom.kt b/plu-domain/src/main/kotlin/com/th/plu/domain/domain/answer/repository/AnswerRepositoryCustom.kt index 5648300..2d9362d 100644 --- a/plu-domain/src/main/kotlin/com/th/plu/domain/domain/answer/repository/AnswerRepositoryCustom.kt +++ b/plu-domain/src/main/kotlin/com/th/plu/domain/domain/answer/repository/AnswerRepositoryCustom.kt @@ -10,7 +10,7 @@ interface AnswerRepositoryCustom { fun findEveryAnswersWithCursorAndPageSize(questionId: Long, lastAnswerId: Long, pageSize: Long): List - fun findPublicAnswersCountByQuestionId(questionId: Long): Long + fun findPublicAnswersCountByQuestionId(questionId: Long): Long? fun findPublicAnswersLikeTopN(questionId: Long, getCount: Long): List } diff --git a/plu-domain/src/main/kotlin/com/th/plu/domain/domain/answer/repository/AnswerRepositoryImpl.kt b/plu-domain/src/main/kotlin/com/th/plu/domain/domain/answer/repository/AnswerRepositoryImpl.kt index e7dab69..35d373d 100644 --- a/plu-domain/src/main/kotlin/com/th/plu/domain/domain/answer/repository/AnswerRepositoryImpl.kt +++ b/plu-domain/src/main/kotlin/com/th/plu/domain/domain/answer/repository/AnswerRepositoryImpl.kt @@ -13,48 +13,48 @@ import org.springframework.stereotype.Repository class AnswerRepositoryImpl(private val queryFactory: JPAQueryFactory) : AnswerRepositoryCustom { override fun findAnswerById(id: Long): Answer? { return queryFactory - .selectFrom(answer) - .where(answer.id.eq(id)) - .fetchOne() + .selectFrom(answer) + .where(answer._id.eq(id)) + .fetchOne() } override fun findEveryAnswersWithCursorAndPageSize(questionId: Long, lastAnswerId: Long, pageSize: Long): List { return queryFactory - .select(QEveryAnswerRetrieveResponse(answer.id, like.answer.id.count(), answer.content)) - .from(answer) - .leftJoin(like).on(like.answer.id.eq(answer.id)) - .where( - answer.isPublic.eq(true), - answer.question.id.eq(questionId), - answer.id.lt(lastAnswerId), - ) - .groupBy(answer.id) - .orderBy(answer.id.desc()) - .limit(pageSize) - .fetch() + .select(QEveryAnswerRetrieveResponse(answer._id, like.answer._id.count(), answer.content)) + .from(answer) + .leftJoin(like).on(like.answer._id.eq(answer._id)) + .where( + answer.isPublic.eq(true), + answer.question._id.eq(questionId), + answer._id.lt(lastAnswerId), + ) + .groupBy(answer._id) + .orderBy(answer._id.desc()) + .limit(pageSize) + .fetch() } - override fun findPublicAnswersCountByQuestionId(questionId: Long): Long { + override fun findPublicAnswersCountByQuestionId(questionId: Long): Long? { return queryFactory - .select(answer.id.count()) - .from(answer) - .where(answer.question.id.eq(questionId)) - .fetchOne()!! + .select(answer._id.count()) + .from(answer) + .where(answer.question._id.eq(questionId)) + .fetchOne() } override fun findPublicAnswersLikeTopN(questionId: Long, getCount: Long): List { return queryFactory - .select(QEveryAnswerRetrieveResponse(answer.id, like.answer.id.count(), answer.content)) - .from(answer) - .leftJoin(like).on(like.answer.id.eq(answer.id)) - .where( - answer.isPublic.eq(true), - answer.question.id.eq(questionId) - ) - .groupBy(answer.id) - .orderBy(like.answer.id.count().desc()) - .limit(getCount) - .fetch() + .select(QEveryAnswerRetrieveResponse(answer._id, like.answer._id.count(), answer.content)) + .from(answer) + .leftJoin(like).on(like.answer._id.eq(answer._id)) + .where( + answer.isPublic.eq(true), + answer.question._id.eq(questionId) + ) + .groupBy(answer._id) + .orderBy(like.answer._id.count().desc()) + .limit(getCount) + .fetch() } override fun existsByMemberIdAndQuestionId(memberId: Long, questionId: Long): Boolean { diff --git a/plu-domain/src/main/kotlin/com/th/plu/domain/domain/question/QuestionExplorer.kt b/plu-domain/src/main/kotlin/com/th/plu/domain/domain/question/QuestionExplorer.kt deleted file mode 100644 index 16ff689..0000000 --- a/plu-domain/src/main/kotlin/com/th/plu/domain/domain/question/QuestionExplorer.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.th.plu.domain.domain.question - -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.repository.QuestionRepository -import org.springframework.stereotype.Component -import java.time.LocalDateTime -import java.time.YearMonth - -@Component -class QuestionExplorer( - private val questionRepository: QuestionRepository, -) { - fun findQuestion(id: Long): Question = - questionRepository.findById(id).orElse(null) - ?: throw NotFoundException(ErrorCode.NOT_FOUND_QUESTION_EXCEPTION, "존재하지 않는 질문 $id 입니다") - - fun findQuestion(date: LocalDateTime): Question = - questionRepository.findByExposedAtOrNull(date) ?: throw InternalServerException( - ErrorCode.DATA_NOT_READY_EXCEPTION, - "($date) 날짜의 질문데이터가 준비되지 않았습니다. " - ) - - fun findMyQuestionsMonthly(memberId: Long, yearMonth: YearMonth): List = - questionRepository.findAllByExposedMonthIn(memberId, yearMonth) - - fun findAnsweredYearMonth(memberId: Long): Set = - questionRepository.findAllExposedAtInAnsweredMonth(memberId) - .map { YearMonth.of(it.year, it.monthValue) } - .toSet() // application 에서 중복 처리중, 500 넘는 warn log 발생시 월별 1건 조회하도록 쿼리 개선 필요! - - fun findTodayQuestion(): Question { - return findQuestion(LocalDateTime.now()) - } -} \ No newline at end of file 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 63d1da9..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 @@ -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 = + questionRepository.findAllByExposedMonthIn(memberId, yearMonth) + + fun findAnsweredYearMonth(memberId: Long): Set = + 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()) } + } \ No newline at end of file diff --git a/plu-domain/src/main/kotlin/com/th/plu/domain/domain/question/repository/QuestionRepositoryCustom.kt b/plu-domain/src/main/kotlin/com/th/plu/domain/domain/question/repository/QuestionRepositoryCustom.kt index 3b4b17e..f9523ff 100644 --- a/plu-domain/src/main/kotlin/com/th/plu/domain/domain/question/repository/QuestionRepositoryCustom.kt +++ b/plu-domain/src/main/kotlin/com/th/plu/domain/domain/question/repository/QuestionRepositoryCustom.kt @@ -1,6 +1,7 @@ package com.th.plu.domain.domain.question.repository import com.th.plu.domain.domain.question.Question +import java.time.LocalDate import java.time.LocalDateTime import java.time.YearMonth @@ -8,11 +9,10 @@ import java.time.YearMonth interface QuestionRepositoryCustom { fun findQuestionById(id: Long): Question? - fun findByExposedAtOrNull(exposedAt: LocalDateTime): Question? + fun findByExposedAtOrNull(startOfPeriod: LocalDateTime, endOfPeriod: LocalDateTime): Question? fun findAllByExposedMonthIn(memberId: Long, yearMonth: YearMonth): List fun findAllExposedAtInAnsweredMonth(memberId: Long): List - fun findTodayQuestion(): Question? } diff --git a/plu-domain/src/main/kotlin/com/th/plu/domain/domain/question/repository/QuestionRepositoryImpl.kt b/plu-domain/src/main/kotlin/com/th/plu/domain/domain/question/repository/QuestionRepositoryImpl.kt index 4811423..40ec8f6 100644 --- a/plu-domain/src/main/kotlin/com/th/plu/domain/domain/question/repository/QuestionRepositoryImpl.kt +++ b/plu-domain/src/main/kotlin/com/th/plu/domain/domain/question/repository/QuestionRepositoryImpl.kt @@ -7,7 +7,6 @@ import com.th.plu.domain.domain.member.QMember.member import com.th.plu.domain.domain.question.QQuestion.question import com.th.plu.domain.domain.question.Question import org.springframework.stereotype.Repository -import java.time.LocalDate import java.time.LocalDateTime import java.time.YearMonth @@ -21,11 +20,12 @@ class QuestionRepositoryImpl(private val queryFactory: JPAQueryFactory) : Questi .fetchOne() } - override fun findByExposedAtOrNull(exposedAt: LocalDateTime): Question? { + + override fun findByExposedAtOrNull(startOfPeriod: LocalDateTime, endOfPeriod: LocalDateTime): Question? { return queryFactory .selectFrom(question) - .where(question.exposedAt.eq(exposedAt)) - .fetchOne() + .where(question.exposedAt.between(startOfPeriod, endOfPeriod)) + .fetchFirst() } override fun findAllByExposedMonthIn(memberId: Long, yearMonth: YearMonth): List { @@ -72,12 +72,4 @@ class QuestionRepositoryImpl(private val queryFactory: JPAQueryFactory) : Questi } } - override fun findTodayQuestion(): Question? { - val today = LocalDate.now() - - return queryFactory - .selectFrom(question) - .where(question.questionDate.eq(today)) - .fetchOne() - } -} +} \ No newline at end of file