라이브 룰렛 태그 메시지 다국어 처리

This commit is contained in:
2025-12-23 13:52:53 +09:00
parent 67b909daed
commit fd94df338b
7 changed files with 172 additions and 52 deletions

View File

@@ -24,7 +24,7 @@ class NewRouletteController(private val service: NewRouletteService) {
@RequestParam creatorId: Long,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
if (member == null) throw SodaException(messageKey = "common.error.bad_credentials")
ApiResponse.ok(service.getAllRoulette(creatorId = creatorId, memberId = member.id!!))
}
@@ -36,7 +36,7 @@ class NewRouletteController(private val service: NewRouletteService) {
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
if (member == null || member.role != MemberRole.CREATOR) {
throw SodaException("로그인 정보를 확인해주세요.")
throw SodaException(messageKey = "common.error.bad_credentials")
}
ApiResponse.ok(service.createRoulette(memberId = member.id!!, request = request))
@@ -49,7 +49,7 @@ class NewRouletteController(private val service: NewRouletteService) {
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
if (member == null || member.role != MemberRole.CREATOR) {
throw SodaException("로그인 정보를 확인해주세요.")
throw SodaException(messageKey = "common.error.bad_credentials")
}
ApiResponse.ok(service.updateRoulette(memberId = member.id!!, request = request))
@@ -60,7 +60,7 @@ class NewRouletteController(private val service: NewRouletteService) {
@RequestParam creatorId: Long,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
): ApiResponse<GetRouletteResponse> {
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
if (member == null) throw SodaException(messageKey = "common.error.bad_credentials")
return ApiResponse.ok(service.getRoulette(creatorId = creatorId, memberId = member.id!!))
}
@@ -70,7 +70,7 @@ class NewRouletteController(private val service: NewRouletteService) {
@RequestBody request: SpinRouletteRequest,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
if (member == null) throw SodaException(messageKey = "common.error.bad_credentials")
ApiResponse.ok(service.spinRoulette(request = request, memberId = member.id!!))
}
@@ -80,7 +80,7 @@ class NewRouletteController(private val service: NewRouletteService) {
@PathVariable id: Long,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
if (member == null) throw SodaException(messageKey = "common.error.bad_credentials")
ApiResponse.ok(service.refundDonation(id, member))
}

View File

@@ -12,6 +12,8 @@ import kr.co.vividnext.sodalive.can.use.CanUsage
import kr.co.vividnext.sodalive.can.use.UseCanCalculateRepository
import kr.co.vividnext.sodalive.can.use.UseCanCalculateStatus
import kr.co.vividnext.sodalive.common.SodaException
import kr.co.vividnext.sodalive.i18n.LangContext
import kr.co.vividnext.sodalive.i18n.SodaMessageSource
import kr.co.vividnext.sodalive.live.room.LiveRoomRepository
import kr.co.vividnext.sodalive.member.Member
import kr.co.vividnext.sodalive.member.MemberRepository
@@ -24,6 +26,8 @@ import org.springframework.transaction.annotation.Transactional
class NewRouletteService(
private val idGenerator: RedisIdGenerator,
private val canPaymentService: CanPaymentService,
private val messageSource: SodaMessageSource,
private val langContext: LangContext,
private val canRepository: CanRepository,
private val repository: NewRouletteRepository,
@@ -33,7 +37,7 @@ class NewRouletteService(
private val useCanCalculateRepository: UseCanCalculateRepository
) {
fun getAllRoulette(creatorId: Long, memberId: Long): List<GetNewRouletteResponse> {
if (creatorId != memberId) throw SodaException("잘못된 요청입니다.")
if (creatorId != memberId) throw SodaException(messageKey = "common.error.invalid_request")
val rouletteList = repository.findByCreatorId(creatorId)
@@ -77,7 +81,7 @@ class NewRouletteService(
val rouletteList = repository.findByCreatorId(creatorId = memberId)
if (rouletteList.isEmpty()) {
throw SodaException("잘못된 요청입니다.")
throw SodaException(messageKey = "common.error.invalid_request")
}
var isActive = false
@@ -104,7 +108,7 @@ class NewRouletteService(
val rouletteList = repository.findByCreatorId(creatorId = creatorId)
if (rouletteList.isEmpty()) {
throw SodaException("룰렛을 사용할 수 없습니다.")
throw SodaException(messageKey = "live.roulette.unavailable")
}
var activeRoulette: NewRoulette? = null
@@ -116,7 +120,7 @@ class NewRouletteService(
}
if (activeRoulette == null || activeRoulette.items.isEmpty()) {
throw SodaException("룰렛을 사용할 수 없습니다.")
throw SodaException(messageKey = "live.roulette.unavailable")
}
return GetRouletteResponse(
@@ -130,19 +134,19 @@ class NewRouletteService(
fun spinRoulette(request: SpinRouletteRequest, memberId: Long): GetRouletteResponse {
// STEP 1 - 라이브 정보 가져오기
val room = roomRepository.findByIdOrNull(request.roomId)
?: throw SodaException("해당하는 라이브가 없습니다.")
?: throw SodaException(messageKey = "live.roulette.live_not_found")
val host = room.member ?: throw SodaException("잘못된 요청입니다.")
val host = room.member ?: throw SodaException(messageKey = "common.error.invalid_request")
if (host.role != MemberRole.CREATOR) {
throw SodaException("주식회사 소다라이브와 계약한\n크리에이터의 룰렛만 사용하실 수 있습니다.")
throw SodaException(messageKey = "live.roulette.creator_contract_only")
}
// STEP 2 - 룰렛 데이터 가져오기
val rouletteList = repository.findByCreatorId(creatorId = host.id!!)
if (rouletteList.isEmpty()) {
throw SodaException("룰렛을 사용할 수 없습니다.")
throw SodaException(messageKey = "live.roulette.unavailable")
}
var activeRoulette: NewRoulette? = null
@@ -154,7 +158,7 @@ class NewRouletteService(
}
if (activeRoulette == null || activeRoulette.items.isEmpty()) {
throw SodaException("룰렛을 사용할 수 없습니다.")
throw SodaException(messageKey = "live.roulette.unavailable")
}
// STEP 3 - 캔 사용
@@ -176,20 +180,23 @@ class NewRouletteService(
@Transactional
fun refundDonation(roomId: Long, member: Member) {
val donator = memberRepository.findByIdOrNull(member.id)
?: throw SodaException("룰렛 돌리기에 실패한 캔이 환불되지 않았습니다\n고객센터로 문의해주세요.")
?: throw SodaException(messageKey = "live.roulette.refund_failed")
val useCan = canRepository.getCanUsedForLiveRoomNotRefund(
memberId = member.id!!,
roomId = roomId,
canUsage = CanUsage.SPIN_ROULETTE
) ?: throw SodaException("룰렛 돌리기에 실패한 캔이 환불되지 않았습니다\n고객센터로 문의해주세요.")
) ?: throw SodaException(messageKey = "live.roulette.refund_failed")
useCan.isRefund = true
val useCanCalculates = useCanCalculateRepository.findByUseCanIdAndStatus(useCan.id!!)
useCanCalculates.forEach {
it.status = UseCanCalculateStatus.REFUND
val charge = Charge(0, it.can, status = ChargeStatus.REFUND_CHARGE)
charge.title = "${it.can}"
val canTitleTemplate = messageSource
.getMessage("live.roulette.can_title", langContext.lang)
.orEmpty()
charge.title = String.format(canTitleTemplate, it.can)
charge.useCan = useCan
when (it.paymentGateway) {
@@ -203,7 +210,7 @@ class NewRouletteService(
status = PaymentStatus.COMPLETE,
paymentGateway = it.paymentGateway
)
payment.method = "룰렛 환불"
payment.method = messageSource.getMessage("live.roulette.refund_method", langContext.lang).orEmpty()
charge.payment = payment
chargeRepository.save(charge)
@@ -212,11 +219,11 @@ class NewRouletteService(
private fun rouletteValidate(can: Int, items: List<RouletteItem>) {
if (can < 5) {
throw SodaException("룰렛 금액은 최소 5캔 입니다.")
throw SodaException(messageKey = "live.roulette.min_can")
}
if (items.size < 2 || items.size > 10) {
throw SodaException("룰렛 옵션은 최소 2개, 최대 10개까지 설정할 수 있습니다.")
throw SodaException(messageKey = "live.roulette.item_count_range")
}
}

View File

@@ -24,7 +24,7 @@ class RouletteController(private val service: RouletteService) {
@RequestParam creatorId: Long,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
if (member == null) throw SodaException(messageKey = "common.error.bad_credentials")
ApiResponse.ok(service.getAllRoulette(creatorId = creatorId, memberId = member.id!!))
}
@@ -36,7 +36,7 @@ class RouletteController(private val service: RouletteService) {
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
if (member == null || member.role != MemberRole.CREATOR) {
throw SodaException("로그인 정보를 확인해주세요.")
throw SodaException(messageKey = "common.error.bad_credentials")
}
ApiResponse.ok(service.createRoulette(memberId = member.id!!, request = request))
@@ -49,7 +49,7 @@ class RouletteController(private val service: RouletteService) {
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
if (member == null || member.role != MemberRole.CREATOR) {
throw SodaException("로그인 정보를 확인해주세요.")
throw SodaException(messageKey = "common.error.bad_credentials")
}
ApiResponse.ok(service.updateRoulette(memberId = member.id!!, request = request))
@@ -60,7 +60,7 @@ class RouletteController(private val service: RouletteService) {
@RequestParam creatorId: Long,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
if (member == null) throw SodaException(messageKey = "common.error.bad_credentials")
ApiResponse.ok(service.getRoulette(creatorId = creatorId, memberId = member.id!!))
}
@@ -70,7 +70,7 @@ class RouletteController(private val service: RouletteService) {
@RequestBody request: SpinRouletteRequestV2,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
if (member == null) throw SodaException(messageKey = "common.error.bad_credentials")
ApiResponse.ok(service.spinRoulette(request = request, member = member))
}
@@ -80,7 +80,7 @@ class RouletteController(private val service: RouletteService) {
@PathVariable id: Long,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
if (member == null) throw SodaException(messageKey = "common.error.bad_credentials")
ApiResponse.ok(service.refundDonation(id, member))
}

View File

@@ -12,6 +12,8 @@ import kr.co.vividnext.sodalive.can.use.CanUsage
import kr.co.vividnext.sodalive.can.use.UseCanCalculateRepository
import kr.co.vividnext.sodalive.can.use.UseCanCalculateStatus
import kr.co.vividnext.sodalive.common.SodaException
import kr.co.vividnext.sodalive.i18n.LangContext
import kr.co.vividnext.sodalive.i18n.SodaMessageSource
import kr.co.vividnext.sodalive.live.room.LiveRoomRepository
import kr.co.vividnext.sodalive.live.room.info.LiveRoomInfoRedisRepository
import kr.co.vividnext.sodalive.live.roulette.NewRoulette
@@ -31,6 +33,8 @@ import kotlin.random.Random
class RouletteService(
private val idGenerator: RedisIdGenerator,
private val canPaymentService: CanPaymentService,
private val messageSource: SodaMessageSource,
private val langContext: LangContext,
private val canRepository: CanRepository,
private val repository: RouletteRepository,
@@ -43,7 +47,7 @@ class RouletteService(
private val tokenLocks: MutableMap<Long, ReentrantReadWriteLock> = mutableMapOf()
fun getAllRoulette(creatorId: Long, memberId: Long): List<GetRouletteResponseV2> {
if (creatorId != memberId) throw SodaException("잘못된 요청입니다.")
if (creatorId != memberId) throw SodaException(messageKey = "common.error.invalid_request")
return repository.findByCreatorId(creatorId)
.sortedBy { it.id }
@@ -88,7 +92,7 @@ class RouletteService(
val rouletteList = repository.findByCreatorId(creatorId = memberId)
if (rouletteList.isEmpty()) {
throw SodaException("잘못된 요청입니다.")
throw SodaException(messageKey = "common.error.invalid_request")
}
var activeRoulette = false
@@ -119,7 +123,7 @@ class RouletteService(
.map { GetRouletteResponseV2(it.id, it.can, it.isActive, it.items) }
if (rouletteList.isEmpty()) {
throw SodaException("룰렛을 사용할 수 없습니다.")
throw SodaException(messageKey = "live.roulette.unavailable")
}
return rouletteList
@@ -129,19 +133,19 @@ class RouletteService(
fun spinRoulette(request: SpinRouletteRequestV2, member: Member): SpinRouletteResponse {
// STEP 1 - 라이브 정보 가져오기
val room = roomRepository.findByIdOrNull(request.roomId)
?: throw SodaException("해당하는 라이브가 없습니다.")
?: throw SodaException(messageKey = "live.roulette.live_not_found")
val host = room.member ?: throw SodaException("잘못된 요청입니다.")
val host = room.member ?: throw SodaException(messageKey = "common.error.invalid_request")
if (host.role != MemberRole.CREATOR) {
throw SodaException("주식회사 소다라이브와 계약한\n크리에이터의 룰렛만 사용하실 수 있습니다.")
throw SodaException(messageKey = "live.roulette.creator_contract_only")
}
// STEP 2 - 룰렛 데이터 가져오기
val roulette = repository.findByIdOrNull(id = request.rouletteId)
if (roulette == null || roulette.items.isEmpty()) {
throw SodaException("룰렛을 사용할 수 없습니다.")
throw SodaException(messageKey = "live.roulette.unavailable")
}
// STEP 3 - 캔 사용
@@ -159,12 +163,15 @@ class RouletteService(
val lock = getOrCreateLock(memberId = member.id!!)
lock.write {
val roomInfo = roomInfoRepository.findByIdOrNull(room.id!!)
?: throw SodaException("해당하는 라이브의 정보가 없습니다.")
?: throw SodaException(messageKey = "live.roulette.live_info_not_found")
val messageTemplate = messageSource
.getMessage("live.roulette.result_message", langContext.lang)
.orEmpty()
roomInfo.addRouletteMessage(
memberId = member.id!!,
nickname = member.nickname,
donationMessage = "[$result] 당첨!"
donationMessage = String.format(messageTemplate, result)
)
roomInfoRepository.save(roomInfo)
@@ -176,20 +183,23 @@ class RouletteService(
@Transactional
fun refundDonation(roomId: Long, member: Member) {
val donator = memberRepository.findByIdOrNull(member.id)
?: throw SodaException("룰렛 돌리기에 실패한 캔이 환불되지 않았습니다\n고객센터로 문의해주세요.")
?: throw SodaException(messageKey = "live.roulette.refund_failed")
val useCan = canRepository.getCanUsedForLiveRoomNotRefund(
memberId = member.id!!,
roomId = roomId,
canUsage = CanUsage.SPIN_ROULETTE
) ?: throw SodaException("룰렛 돌리기에 실패한 캔이 환불되지 않았습니다\n고객센터로 문의해주세요.")
) ?: throw SodaException(messageKey = "live.roulette.refund_failed")
useCan.isRefund = true
val useCanCalculates = useCanCalculateRepository.findByUseCanIdAndStatus(useCan.id!!)
useCanCalculates.forEach {
it.status = UseCanCalculateStatus.REFUND
val charge = Charge(0, it.can, status = ChargeStatus.REFUND_CHARGE)
charge.title = "${it.can}"
val canTitleTemplate = messageSource
.getMessage("live.roulette.can_title", langContext.lang)
.orEmpty()
charge.title = String.format(canTitleTemplate, it.can)
charge.useCan = useCan
when (it.paymentGateway) {
@@ -203,7 +213,7 @@ class RouletteService(
status = PaymentStatus.COMPLETE,
paymentGateway = it.paymentGateway
)
payment.method = "룰렛 환불"
payment.method = messageSource.getMessage("live.roulette.refund_method", langContext.lang).orEmpty()
charge.payment = payment
chargeRepository.save(charge)
@@ -234,16 +244,16 @@ class RouletteService(
private fun rouletteValidate(can: Int, items: List<RouletteItem>) {
if (can < 5) {
throw SodaException("룰렛 금액은 최소 5캔 입니다.")
throw SodaException(messageKey = "live.roulette.min_can")
}
if (items.size < 2 || items.size > 10) {
throw SodaException("룰렛 옵션은 최소 2개, 최대 10개까지 설정할 수 있습니다.")
throw SodaException(messageKey = "live.roulette.item_count_range")
}
val totalPercentage = items.map { it.percentage }.sum()
if (totalPercentage > 100.1f || totalPercentage <= 99.99f) {
throw SodaException("확률이 100%가 아닙니다")
throw SodaException(messageKey = "live.roulette.probability_invalid")
}
}