diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/content/comment/AudioContentCommentController.kt b/src/main/kotlin/kr/co/vividnext/sodalive/content/comment/AudioContentCommentController.kt index f603fd7..593758f 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/content/comment/AudioContentCommentController.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/content/comment/AudioContentCommentController.kt @@ -43,6 +43,7 @@ class AudioContentCommentController( userActionService.recordAction( memberId = member.id!!, + isAuth = member.auth != null, actionType = ActionType.CONTENT_COMMENT, contentCommentId = commentId, pushTokenList = pushTokenList @@ -50,6 +51,7 @@ class AudioContentCommentController( userActionService.recordAction( memberId = member.id!!, + isAuth = member.auth != null, actionType = ActionType.ORDER_CONTENT_COMMENT, contentId = request.contentId, contentCommentId = commentId, diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/member/MemberController.kt b/src/main/kotlin/kr/co/vividnext/sodalive/member/MemberController.kt index 11c893c..e7cd05b 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/member/MemberController.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/member/MemberController.kt @@ -65,6 +65,7 @@ class MemberController( userActionService.recordAction( memberId = response.memberId, + isAuth = false, actionType = ActionType.SIGN_UP, pushTokenList = if (request.pushToken != null) { listOf(request.pushToken) @@ -358,6 +359,7 @@ class MemberController( if (response.isNew) { userActionService.recordAction( memberId = response.memberId, + isAuth = false, actionType = ActionType.SIGN_UP, pushTokenList = if (request.pushToken != null) { listOf(request.pushToken) @@ -393,6 +395,7 @@ class MemberController( if (response.isNew) { userActionService.recordAction( memberId = response.memberId, + isAuth = false, actionType = ActionType.SIGN_UP, pushTokenList = if (request.pushToken != null) { listOf(request.pushToken) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/member/auth/AuthController.kt b/src/main/kotlin/kr/co/vividnext/sodalive/member/auth/AuthController.kt index 17366f5..50f8cbb 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/member/auth/AuthController.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/member/auth/AuthController.kt @@ -40,6 +40,7 @@ class AuthController( val pushTokenList = memberService.getPushTokenList(recipient = memberId) userActionService.recordAction( memberId = member.id!!, + isAuth = true, actionType = ActionType.USER_AUTHENTICATION, pushTokenList = pushTokenList ) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/useraction/UserActionController.kt b/src/main/kotlin/kr/co/vividnext/sodalive/useraction/UserActionController.kt index 91ae58c..1a87e08 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/useraction/UserActionController.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/useraction/UserActionController.kt @@ -27,6 +27,7 @@ class UserActionController( val pushTokenList = memberService.getPushTokenList(recipient = memberId) service.recordAction( memberId = memberId, + isAuth = member.auth != null, actionType = request.actionType, pushTokenList = pushTokenList ) 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 11697a6..1025369 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/useraction/UserActionService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/useraction/UserActionService.kt @@ -31,6 +31,7 @@ class UserActionService( fun recordAction( memberId: Long, + isAuth: Boolean, actionType: ActionType, contentId: Long? = null, contentCommentId: Long? = null, @@ -49,96 +50,98 @@ class UserActionService( repository.flush() } - try { - transactionTemplate.execute { - val policy = policyRepository.findByActionTypeAndIsActiveTrue(actionType, now) - if (policy != null) { - val policyType = policy.policyType - val todayAt15 = now.toLocalDate().atTime(15, 0) - val policyTypeDailyStartDate = if (now.toLocalTime().isBefore(todayAt15.toLocalTime())) { - now.toLocalDate().minusDays(1).atTime(15, 0) - } else { - todayAt15 - } + if (isAuth) { + try { + transactionTemplate.execute { + val policy = policyRepository.findByActionTypeAndIsActiveTrue(actionType, now) + if (policy != null) { + val policyType = policy.policyType + val todayAt15 = now.toLocalDate().atTime(15, 0) + val policyTypeDailyStartDate = if (now.toLocalTime().isBefore(todayAt15.toLocalTime())) { + now.toLocalDate().minusDays(1).atTime(15, 0) + } else { + todayAt15 + } - val isValidPolicyTypeDailyAndDailyStartDateAfterPolicyStartDate = - policyType == PolicyType.DAILY && policyTypeDailyStartDate >= policy.startDate - val order = if (contentId != null) { - orderRepository.findByMemberIdAndContentId( + val isValidPolicyTypeDailyAndDailyStartDateAfterPolicyStartDate = + policyType == PolicyType.DAILY && policyTypeDailyStartDate >= policy.startDate + val order = if (contentId != null) { + orderRepository.findByMemberIdAndContentId( + memberId = memberId, + contentId = contentId, + createdAt = if (isValidPolicyTypeDailyAndDailyStartDateAfterPolicyStartDate) { + policyTypeDailyStartDate + } else { + policy.startDate + } + ) + } else { + null + } + if (actionType == ActionType.ORDER_CONTENT_COMMENT && order == null) return@execute + + val actionCount = repository.countByMemberIdAndActionTypeAndCreatedAtBetween( memberId = memberId, - contentId = contentId, - createdAt = if (isValidPolicyTypeDailyAndDailyStartDateAfterPolicyStartDate) { + actionType = actionType, + startDate = if (isValidPolicyTypeDailyAndDailyStartDateAfterPolicyStartDate) { policyTypeDailyStartDate } else { policy.startDate + }, + endDate = policy.endDate ?: now + ) + if (actionCount < policy.threshold) return@execute + + val grantedCount = grantLogRepository.countByMemberIdAndPolicyIdAndStartDate( + memberId, + policy.id!!, + startDate = if (isValidPolicyTypeDailyAndDailyStartDateAfterPolicyStartDate) { + policyTypeDailyStartDate + } else { + policy.startDate + }, + orderId = order?.id + ) + if (grantedCount >= policy.availableCount) return@execute + + val point = if (actionType == ActionType.ORDER_CONTENT_COMMENT && order != null) { + order.can + } else { + policy.pointAmount + } + + if (point > 0) { + grantLogRepository.save( + PointGrantLog( + memberId = memberId, + point = point, + actionType = actionType, + policyId = policy.id!!, + orderId = order?.id + ) + ) + + memberPointRepository.save( + MemberPoint( + memberId = memberId, + point = point, + actionType = actionType, + expiresAt = now.plusDays(3) + ) + ) + + if (pushTokenList.isNotEmpty()) { + fcmService.sendPointGranted( + pushTokenList, + point + ) } - ) - } else { - null - } - if (actionType == ActionType.ORDER_CONTENT_COMMENT && order == null) return@execute - - val actionCount = repository.countByMemberIdAndActionTypeAndCreatedAtBetween( - memberId = memberId, - actionType = actionType, - startDate = if (isValidPolicyTypeDailyAndDailyStartDateAfterPolicyStartDate) { - policyTypeDailyStartDate - } else { - policy.startDate - }, - endDate = policy.endDate ?: now - ) - if (actionCount < policy.threshold) return@execute - - val grantedCount = grantLogRepository.countByMemberIdAndPolicyIdAndStartDate( - memberId, - policy.id!!, - startDate = if (isValidPolicyTypeDailyAndDailyStartDateAfterPolicyStartDate) { - policyTypeDailyStartDate - } else { - policy.startDate - }, - orderId = order?.id - ) - if (grantedCount >= policy.availableCount) return@execute - - val point = if (actionType == ActionType.ORDER_CONTENT_COMMENT && order != null) { - order.can - } else { - policy.pointAmount - } - - if (point > 0) { - grantLogRepository.save( - PointGrantLog( - memberId = memberId, - point = point, - actionType = actionType, - policyId = policy.id!!, - orderId = order?.id - ) - ) - - memberPointRepository.save( - MemberPoint( - memberId = memberId, - point = point, - actionType = actionType, - expiresAt = now.plusDays(3) - ) - ) - - if (pushTokenList.isNotEmpty()) { - fcmService.sendPointGranted( - pushTokenList, - point - ) } } } + } catch (e: Exception) { + logger.warn("포인트 지급 또는 알림 실패: ${e.message}") } - } catch (e: Exception) { - logger.warn("포인트 지급 또는 알림 실패: ${e.message}") } } }