Skip to content

Commit

Permalink
fix: 미결제 팀원이 있는 경우에도 신청으로 처리되는 문제 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
23tae committed Dec 5, 2024
1 parent b94ff7d commit 690452a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/main/kotlin/uoslife/servermeeting/match/dao/MatchedDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import uoslife.servermeeting.meetingteam.entity.MeetingTeam
import uoslife.servermeeting.meetingteam.entity.QMeetingTeam.meetingTeam
import uoslife.servermeeting.meetingteam.entity.QUserTeam.userTeam
import uoslife.servermeeting.meetingteam.entity.enums.TeamType
import uoslife.servermeeting.payment.entity.QPayment
import uoslife.servermeeting.payment.entity.enums.PaymentStatus

@Repository
Expand All @@ -35,25 +34,30 @@ class MatchedDao(private val queryFactory: JPAQueryFactory) {
}

fun findUserParticipation(userId: Long, season: Int): MeetingParticipationResponse {
val result =
val teams =
queryFactory
.select(userTeam.team.id, userTeam.team.type)
.from(userTeam)
.selectFrom(userTeam)
.join(userTeam.team)
.join(QPayment.payment)
.on(QPayment.payment.meetingTeam.eq(userTeam.team))
.where(
userTeam.user.id.eq(userId),
userTeam.team.season.eq(season),
QPayment.payment.status.eq(PaymentStatus.SUCCESS)
)
.fetchJoin() // team을 미리 로딩
.leftJoin(userTeam.team.payments)
.fetchJoin() // payments도 미리 로딩
.where(userTeam.user.id.eq(userId), userTeam.team.season.eq(season))
.fetch()

val participations = result.groupBy { it.get(userTeam.team.type) }
val participations =
teams
.groupBy { it.team.type }
.mapValues { (_, userTeams) ->
userTeams.all { userTeam ->
val payments = userTeam.team.payments
payments?.isNotEmpty() == true &&
payments.all { it.status == PaymentStatus.SUCCESS }
}
}

return MeetingParticipationResponse(
single = participations[TeamType.SINGLE]?.isNotEmpty() ?: false,
triple = participations[TeamType.TRIPLE]?.isNotEmpty() ?: false,
single = participations[TeamType.SINGLE] ?: false,
triple = participations[TeamType.TRIPLE] ?: false,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import uoslife.servermeeting.meetingteam.exception.GenderNotUpdatedException
import uoslife.servermeeting.meetingteam.exception.MeetingTeamNotFoundException
import uoslife.servermeeting.meetingteam.service.impl.SingleMeetingService
import uoslife.servermeeting.meetingteam.service.impl.TripleMeetingService
import uoslife.servermeeting.payment.entity.enums.PaymentStatus
import uoslife.servermeeting.payment.exception.PaymentNotFoundException
import uoslife.servermeeting.user.entity.User
import uoslife.servermeeting.user.entity.enums.GenderType
import uoslife.servermeeting.user.exception.UserNotFoundException
Expand Down Expand Up @@ -46,6 +48,14 @@ class MatchingService(
userTeamDao.findUserWithTeamTypeAndSeason(userId, teamType, season)
?: throw MeetingTeamNotFoundException()
val meetingTeam = userTeam.team

val hasInvalidPayment =
meetingTeam.payments?.any { payment -> payment.status != PaymentStatus.SUCCESS }
?: false
if (hasInvalidPayment) {
throw PaymentNotFoundException()
}

try {
val match = getMatchByGender(userTeam.user, meetingTeam)
val opponentTeam = getOpponentTeamByGender(userTeam.user, match)
Expand Down

0 comments on commit 690452a

Please sign in to comment.