Skip to content

Commit

Permalink
Merge branch 'main' into refactor/match-api-endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
23tae committed Dec 6, 2024
1 parent 8789da8 commit 4433b14
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/main/kotlin/uoslife/servermeeting/admin/api/AdminApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,11 @@ class AdminApi(
val requestInfo = requestUtils.toRequestInfoDto(request)
return ResponseEntity.status(HttpStatus.OK).body(adminService.refundPayment(requestInfo))
}

@Operation(summary = "매칭 결과 캐시 웜업 API", description = "결제 완료된 매칭 데이터를 캐시에 저장합니다")
@PostMapping("/cache/warmup")
fun triggerCacheWarmup(@RequestParam season: Int): ResponseEntity<Unit> {
adminService.warmUpCacheAsync(season)
return ResponseEntity.status(HttpStatus.NO_CONTENT).build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import java.time.Duration
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.data.redis.core.RedisTemplate
import org.springframework.scheduling.annotation.Async
import org.springframework.stereotype.Service
import uoslife.servermeeting.match.service.MatchingService
import uoslife.servermeeting.meetingteam.dao.UserTeamDao
import uoslife.servermeeting.global.common.dto.RequestInfoDto
import uoslife.servermeeting.payment.dto.response.PaymentResponseDto
import uoslife.servermeeting.payment.service.PaymentService
Expand All @@ -17,7 +20,9 @@ import uoslife.servermeeting.verification.util.VerificationUtils
class AdminService(
private val redisTemplate: RedisTemplate<String, Any>,
private val userService: UserService,
@Qualifier("PortOneService") private val paymentService: PaymentService
@Qualifier("PortOneService") private val paymentService: PaymentService,
private val matchingService: MatchingService,
private val userTeamDao: UserTeamDao,
) {
companion object {
private val logger = LoggerFactory.getLogger(AdminService::class.java)
Expand Down Expand Up @@ -45,4 +50,18 @@ class AdminService(
logger.info("[ADMIN-매칭 실패 유저 환불] $requestInfo")
return result
}

@Async
fun warmUpCacheAsync(season: Int) {
logger.info("[캐시 웜업 시작]")
val participants = userTeamDao.findAllParticipantsBySeasonAndType(season)
participants.forEach { participant ->
try {
matchingService.getMatchInfo(participant.userId, participant.teamType, season)
} catch (e: Exception) {
logger.info("[캐시 웜업 실패] userId: ${participant.userId} message: ${e.message}")
}
}
logger.info("[캐시 웜업 성공] 대상 인원: ${participants.size}")
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package uoslife.servermeeting.meetingteam.dao

import com.querydsl.core.types.Projections
import com.querydsl.jpa.impl.JPAQueryFactory
import jakarta.persistence.EntityManager
import jakarta.transaction.Transactional
import org.springframework.stereotype.Repository
import uoslife.servermeeting.meetingteam.dto.ParticipantInfo
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.UserTeam
import uoslife.servermeeting.meetingteam.entity.enums.TeamType
import uoslife.servermeeting.payment.entity.QPayment.payment
import uoslife.servermeeting.payment.entity.enums.PaymentStatus
import uoslife.servermeeting.user.entity.QUser.user
import uoslife.servermeeting.user.entity.QUserInformation.userInformation
import uoslife.servermeeting.user.entity.User
Expand Down Expand Up @@ -108,4 +112,25 @@ class UserTeamDao(
.fetchJoin()
.fetchOne()
}

fun findAllParticipantsBySeasonAndType(season: Int): List<ParticipantInfo> {
return queryFactory
.select(
Projections.constructor(
ParticipantInfo::class.java,
userTeam.user.id,
userTeam.team.type,
)
)
.from(userTeam)
.join(userTeam.team, meetingTeam)
.leftJoin(payment)
.on(payment.meetingTeam.eq(meetingTeam))
.where(
meetingTeam.season.eq(season),
)
.groupBy(userTeam.user.id, userTeam.team.type)
.having(payment.status.eq(PaymentStatus.SUCCESS).count().eq(payment.count()))
.fetch()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package uoslife.servermeeting.meetingteam.dto

import uoslife.servermeeting.meetingteam.entity.enums.TeamType

data class ParticipantInfo(val userId: Long, val teamType: TeamType)

0 comments on commit 4433b14

Please sign in to comment.