From c25f5fe2852a0378fd8d1f4e0962946ce461bf82 Mon Sep 17 00:00:00 2001 From: 210-reverof Date: Wed, 21 Aug 2024 14:51:23 +0900 Subject: [PATCH] feat: Add generating condition --- .../pic/vote/applicationservice/VoteApplicationService.kt | 4 +++- .../com/mashup/pic/domain/redis/RedisMessageListener.kt | 4 +++- .../kotlin/com/mashup/pic/domain/result/ResultRepository.kt | 2 ++ .../main/kotlin/com/mashup/pic/domain/result/ResultService.kt | 4 ++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pic-api/src/main/kotlin/com/mashup/pic/vote/applicationservice/VoteApplicationService.kt b/pic-api/src/main/kotlin/com/mashup/pic/vote/applicationservice/VoteApplicationService.kt index 31459d5..d7114da 100644 --- a/pic-api/src/main/kotlin/com/mashup/pic/vote/applicationservice/VoteApplicationService.kt +++ b/pic-api/src/main/kotlin/com/mashup/pic/vote/applicationservice/VoteApplicationService.kt @@ -34,7 +34,9 @@ class VoteApplicationService( voteService.markVoted(request.userId, request.eventId) if (voteService.hasEveryoneVoted(request.eventId)) { - resultService.generateResult(request.eventId) + if (!resultService.hasResult(request.eventId)) { + resultService.generateResult(request.eventId) + } eventService.endEventVoting(request.eventId) } diff --git a/pic-domain/src/main/kotlin/com/mashup/pic/domain/redis/RedisMessageListener.kt b/pic-domain/src/main/kotlin/com/mashup/pic/domain/redis/RedisMessageListener.kt index 8e91b64..ade95ed 100644 --- a/pic-domain/src/main/kotlin/com/mashup/pic/domain/redis/RedisMessageListener.kt +++ b/pic-domain/src/main/kotlin/com/mashup/pic/domain/redis/RedisMessageListener.kt @@ -25,7 +25,9 @@ class RedisMessageListener( when (ChannelTopic.from(eventInfo.topic)) { ChannelTopic.EVENT_OPEN -> eventService.endEventUploading(eventInfo.eventId) ChannelTopic.VOTE_OPEN -> { - resultService.generateResult(eventInfo.eventId) + if (!resultService.hasResult(eventInfo.eventId)) { + resultService.generateResult(eventInfo.eventId) + } eventService.endEventVoting(eventInfo.eventId) } } diff --git a/pic-domain/src/main/kotlin/com/mashup/pic/domain/result/ResultRepository.kt b/pic-domain/src/main/kotlin/com/mashup/pic/domain/result/ResultRepository.kt index ea89c9a..f6a7c19 100644 --- a/pic-domain/src/main/kotlin/com/mashup/pic/domain/result/ResultRepository.kt +++ b/pic-domain/src/main/kotlin/com/mashup/pic/domain/result/ResultRepository.kt @@ -4,4 +4,6 @@ import org.springframework.data.jpa.repository.JpaRepository interface ResultRepository : JpaRepository { fun findAllByEventIdOrderByImageOrderAsc(eventId: Long): List + + fun findAllByEventId(eventId: Long): List } diff --git a/pic-domain/src/main/kotlin/com/mashup/pic/domain/result/ResultService.kt b/pic-domain/src/main/kotlin/com/mashup/pic/domain/result/ResultService.kt index e2d563b..e5d5f3c 100644 --- a/pic-domain/src/main/kotlin/com/mashup/pic/domain/result/ResultService.kt +++ b/pic-domain/src/main/kotlin/com/mashup/pic/domain/result/ResultService.kt @@ -59,6 +59,10 @@ class ResultService( ) } + fun hasResult(eventId: Long): Boolean { + return resultRepository.findAllByEventId(eventId).isNotEmpty() + } + private fun getImageOptionById(imageOptionId: Long): EventImageOption { return eventImageOptionRepository.findByIdOrNull(imageOptionId) ?: throw PicException.of(PicExceptionType.ARGUMENT_NOT_VALID, "없는 이미지 항목")