Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add generating condition #73

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading