Skip to content

Commit

Permalink
Merge pull request #73 from mash-up-kr/fix/generate-option
Browse files Browse the repository at this point in the history
feat: Add generating condition
  • Loading branch information
210-reverof authored Aug 21, 2024
2 parents c711f53 + c25f5fe commit b75342c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ import org.springframework.data.jpa.repository.JpaRepository

interface ResultRepository : JpaRepository<Result, Long> {
fun findAllByEventIdOrderByImageOrderAsc(eventId: Long): List<Result>

fun findAllByEventId(eventId: Long): List<Result>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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, "없는 이미지 항목")
Expand Down

0 comments on commit b75342c

Please sign in to comment.