diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/point/PointGrantLogRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/point/PointGrantLogRepository.kt index 8862ab6..52a57c4 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/point/PointGrantLogRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/point/PointGrantLogRepository.kt @@ -8,21 +8,35 @@ import java.time.LocalDateTime interface PointGrantLogRepository : JpaRepository, PointGrantLogQueryRepository interface PointGrantLogQueryRepository { - fun countByMemberIdAndPolicyIdAndStartDate(memberId: Long, policyId: Long, startDate: LocalDateTime): Int + fun countByMemberIdAndPolicyIdAndStartDate( + memberId: Long, + policyId: Long, + startDate: LocalDateTime, + orderId: Long? = null + ): Int } class PointGrantLogQueryRepositoryImpl( private val queryFactory: JPAQueryFactory ) : PointGrantLogQueryRepository { - override fun countByMemberIdAndPolicyIdAndStartDate(memberId: Long, policyId: Long, startDate: LocalDateTime): Int { + override fun countByMemberIdAndPolicyIdAndStartDate( + memberId: Long, + policyId: Long, + startDate: LocalDateTime, + orderId: Long? + ): Int { + var where = pointGrantLog.memberId.eq(memberId) + .and(pointGrantLog.policyId.eq(policyId)) + .and(pointGrantLog.createdAt.goe(startDate)) + + if (orderId != null) { + where = where.and(pointGrantLog.orderId.eq(orderId)) + } + return queryFactory .select(pointGrantLog.id) .from(pointGrantLog) - .where( - pointGrantLog.memberId.eq(memberId), - pointGrantLog.policyId.eq(policyId), - pointGrantLog.createdAt.goe(startDate) - ) + .where(where) .fetch() .size } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/useraction/UserActionService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/useraction/UserActionService.kt index 8e8d913..a0e92f5 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/useraction/UserActionService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/useraction/UserActionService.kt @@ -97,7 +97,8 @@ class UserActionService( policyTypeDailyStartDate } else { policy.startDate - } + }, + orderId = order?.id ) if (grantedCount >= policy.availableCount) return@execute