다국어 메시지 분리 적용

This commit is contained in:
2025-12-23 16:19:04 +09:00
parent 39d13ab7c3
commit f429ffbbbe
7 changed files with 138 additions and 42 deletions

View File

@@ -30,7 +30,7 @@ class LiveRecommendController(private val service: LiveRecommendService) {
fun getFollowingChannelList(
@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.getFollowingChannelList(member))
}
@@ -40,7 +40,7 @@ class LiveRecommendController(private val service: LiveRecommendService) {
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?,
pageable: Pageable
) = run {
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
if (member == null) throw SodaException(messageKey = "common.error.bad_credentials")
ApiResponse.ok(service.getFollowingAllChannelList(member, pageable))
}

View File

@@ -21,7 +21,7 @@ class LiveReservationController(private val service: LiveReservationService) {
@RequestBody request: MakeLiveReservationRequest,
@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.makeReservation(request, member.id!!))
}
@@ -32,7 +32,7 @@ class LiveReservationController(private val service: LiveReservationService) {
@RequestParam(value = "timezone") timezone: String,
@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.getReservationList(member.id!!, isActive, timezone))
}
@@ -42,7 +42,7 @@ class LiveReservationController(private val service: LiveReservationService) {
@RequestParam(value = "timezone") timezone: String,
@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.getReservation(id, member.id!!, timezone))
}
@@ -51,7 +51,7 @@ class LiveReservationController(private val service: LiveReservationService) {
@RequestBody request: CancelLiveReservationRequest,
@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.cancelReservation(request, member.id!!))
}
}

View File

@@ -3,6 +3,8 @@ package kr.co.vividnext.sodalive.live.reservation
import kr.co.vividnext.sodalive.can.payment.CanPaymentService
import kr.co.vividnext.sodalive.can.use.CanUsage
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.LiveRoomType
import kr.co.vividnext.sodalive.member.MemberRepository
@@ -21,32 +23,36 @@ class LiveReservationService(
private val memberRepository: MemberRepository,
private val canPaymentService: CanPaymentService,
private val liveReservationCancelRepository: LiveReservationCancelRepository,
private val messageSource: SodaMessageSource,
private val langContext: LangContext,
@Value("\${cloud.aws.cloud-front.host}")
private val cloudFrontHost: String
) {
fun makeReservation(request: MakeLiveReservationRequest, memberId: Long): MakeLiveReservationResponse {
val room = liveRoomRepository.findByIdOrNull(id = request.roomId)
?: throw SodaException(message = "잘못된 요청입니다.\n다시 시도해 주세요.")
?: throw SodaException(messageKey = "live.reservation.invalid_request_retry")
val member = memberRepository.findByIdOrNull(id = memberId)
?: throw SodaException(message = "로그인 정보를 확인해주세요.")
?: throw SodaException(messageKey = "common.error.bad_credentials")
if (
room.member!!.id!! != memberId &&
room.type == LiveRoomType.PRIVATE &&
(request.password == null || request.password != room.password)
) {
throw SodaException("비밀번호가 일치하지 않습니다.\n다시 확인 후 입력해주세요.")
throw SodaException(messageKey = "live.room.password_mismatch")
}
if (repository.isExistsReservation(roomId = request.roomId, memberId = memberId)) {
throw SodaException("이미 예약한 라이브 입니다.")
throw SodaException(messageKey = "live.reservation.already_reserved")
}
val haveCan = member.getChargeCan(request.container) + member.getRewardCan(request.container)
if (haveCan < room.price) {
throw SodaException("${room.price - haveCan}캔이 부족합니다. 충전 후 이용해 주세요.")
val messageTemplate = messageSource.getMessage("live.room.insufficient_can", langContext.lang).orEmpty()
val message = String.format(messageTemplate, room.price - haveCan)
throw SodaException(message = message)
}
if (room.price > 0) {
@@ -67,16 +73,21 @@ class LiveReservationService(
val beginDateTime = room.beginDateTime
.atZone(ZoneId.of("UTC"))
.withZoneSameInstant(ZoneId.of(request.timezone))
val reservationDateFormat = messageSource.getMessage(
"live.reservation.datetime_format",
langContext.lang
).orEmpty()
return MakeLiveReservationResponse(
reservationId = reservation.id!!,
nickname = room.member!!.nickname,
title = room.title,
beginDateString = beginDateTime.format(DateTimeFormatter.ofPattern("yyyy년 M월 d일 (E), a hh:mm")),
beginDateString = beginDateTime.format(DateTimeFormatter.ofPattern(reservationDateFormat)),
price = if (room.price > 0) {
"${room.price}"
val priceTemplate = messageSource.getMessage("live.room.can_title", langContext.lang).orEmpty()
String.format(priceTemplate, room.price)
} else {
"무료"
messageSource.getMessage("live.reservation.price_free", langContext.lang).orEmpty()
},
haveCan = haveCan,
useCan = room.price,
@@ -85,6 +96,10 @@ class LiveReservationService(
}
fun getReservationList(memberId: Long, active: Boolean, timezone: String): List<GetLiveReservationResponse> {
val detailDateFormat = messageSource.getMessage(
"live.room.datetime_format_detail",
langContext.lang
).orEmpty()
return repository
.getReservationListByMemberId(memberId, active)
.asSequence()
@@ -105,7 +120,7 @@ class LiveReservationService(
price = it.room!!.price,
masterNickname = it.room!!.member!!.nickname,
beginDateTime = beginDateTime.format(
DateTimeFormatter.ofPattern("yyyy.MM.dd E hh:mm a")
DateTimeFormatter.ofPattern(detailDateFormat)
),
cancelable = beginDateTime.minusHours(4).isAfter(
LocalDateTime.now()
@@ -119,8 +134,12 @@ class LiveReservationService(
fun getReservation(reservationId: Long, memberId: Long, timezone: String): GetLiveReservationResponse {
val reservation = repository.getReservationByReservationAndMemberId(reservationId, memberId)
?: throw SodaException("잘못된 예약정보 입니다.")
?: throw SodaException(messageKey = "live.reservation.invalid_reservation")
val detailDateFormat = messageSource.getMessage(
"live.room.datetime_format_detail",
langContext.lang
).orEmpty()
val beginDateTime = reservation.room!!.beginDateTime
.atZone(ZoneId.of("UTC"))
.withZoneSameInstant(ZoneId.of(timezone))
@@ -137,7 +156,7 @@ class LiveReservationService(
price = reservation.room!!.price,
masterNickname = reservation.room!!.member!!.nickname,
beginDateTime = beginDateTime.format(
DateTimeFormatter.ofPattern("yyyy.MM.dd E hh:mm a")
DateTimeFormatter.ofPattern(detailDateFormat)
),
cancelable = beginDateTime.minusHours(4).isAfter(
LocalDateTime.now()
@@ -150,22 +169,22 @@ class LiveReservationService(
@Transactional
fun cancelReservation(request: CancelLiveReservationRequest, memberId: Long) {
if (request.reason.isBlank()) {
throw SodaException("취소사유를 입력하세요.")
throw SodaException(messageKey = "live.room.cancel_reason_required")
}
val reservation = repository.findByIdOrNull(request.reservationId)
?: throw SodaException("잘못된 예약정보 입니다.")
?: throw SodaException(messageKey = "live.reservation.invalid_reservation")
if (reservation.member == null || reservation.member!!.id!! != memberId) {
throw SodaException("잘못된 예약정보 입니다.")
throw SodaException(messageKey = "live.reservation.invalid_reservation")
}
if (reservation.room == null || reservation.room?.id == null) {
throw SodaException("잘못된 예약정보 입니다.")
throw SodaException(messageKey = "live.reservation.invalid_reservation")
}
if (reservation.room!!.beginDateTime.isBefore(LocalDateTime.now().plusHours(4))) {
throw SodaException("라이브 시작 4시간 이내에는 예약취소가 불가능 합니다.")
throw SodaException(messageKey = "live.reservation.cancel_not_allowed_within_4_hours")
}
if (reservation.room!!.price > 0) {