콘텐츠 메시지 다국어 처리
This commit is contained in:
@@ -25,7 +25,7 @@ class AudioContentCommentController(
|
||||
@RequestBody request: RegisterCommentRequest,
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
||||
) = run {
|
||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
||||
if (member == null) throw SodaException(messageKey = "common.error.bad_credentials")
|
||||
|
||||
val commentId = service.registerComment(
|
||||
comment = request.comment,
|
||||
@@ -62,7 +62,7 @@ class AudioContentCommentController(
|
||||
@RequestBody request: ModifyCommentRequest,
|
||||
@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.modifyComment(request = request, member = member))
|
||||
}
|
||||
@@ -74,7 +74,7 @@ class AudioContentCommentController(
|
||||
@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.getCommentList(
|
||||
@@ -93,7 +93,7 @@ class AudioContentCommentController(
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?,
|
||||
pageable: Pageable
|
||||
): ApiResponse<GetAudioContentCommentListResponse> {
|
||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
||||
if (member == null) throw SodaException(messageKey = "common.error.bad_credentials")
|
||||
|
||||
return ApiResponse.ok(
|
||||
service.getCommentReplyList(
|
||||
|
||||
@@ -7,6 +7,8 @@ import kr.co.vividnext.sodalive.content.LanguageDetectTargetType
|
||||
import kr.co.vividnext.sodalive.content.order.OrderRepository
|
||||
import kr.co.vividnext.sodalive.fcm.FcmEvent
|
||||
import kr.co.vividnext.sodalive.fcm.FcmEventType
|
||||
import kr.co.vividnext.sodalive.i18n.LangContext
|
||||
import kr.co.vividnext.sodalive.i18n.SodaMessageSource
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import kr.co.vividnext.sodalive.member.block.BlockMemberRepository
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
@@ -24,6 +26,8 @@ class AudioContentCommentService(
|
||||
private val audioContentRepository: AudioContentRepository,
|
||||
private val applicationEventPublisher: ApplicationEventPublisher,
|
||||
private val orderRepository: OrderRepository,
|
||||
private val messageSource: SodaMessageSource,
|
||||
private val langContext: LangContext,
|
||||
|
||||
@Value("\${cloud.aws.cloud-front.host}")
|
||||
private val cloudFrontHost: String
|
||||
@@ -38,11 +42,13 @@ class AudioContentCommentService(
|
||||
languageCode: String?
|
||||
): Long {
|
||||
val audioContent = audioContentRepository.findByIdOrNull(id = audioContentId)
|
||||
?: throw SodaException("잘못된 콘텐츠 입니다.\n다시 시도해 주세요.")
|
||||
?: throw SodaException(messageKey = "content.error.invalid_content_retry")
|
||||
|
||||
val creator = audioContent.member!!
|
||||
val isBlocked = blockMemberRepository.isBlocked(blockedMemberId = member.id!!, memberId = creator.id!!)
|
||||
if (isBlocked) throw SodaException("${creator.nickname}님의 요청으로 댓글쓰기가 제한됩니다.")
|
||||
if (isBlocked) {
|
||||
throw SodaException(formatMessage("content.comment.error.blocked_by_creator", creator.nickname))
|
||||
}
|
||||
|
||||
val (isExistsAudioContent, _) = orderRepository.isExistOrderedAndOrderType(
|
||||
memberId = member.id!!,
|
||||
@@ -50,7 +56,7 @@ class AudioContentCommentService(
|
||||
)
|
||||
|
||||
if (isSecret && !isExistsAudioContent) {
|
||||
throw SodaException("콘텐츠 구매 후 비밀댓글을 등록할 수 있습니다.")
|
||||
throw SodaException(messageKey = "content.comment.error.secret_requires_purchase")
|
||||
}
|
||||
|
||||
val audioContentComment = AudioContentComment(comment = comment, languageCode = languageCode, isSecret = isSecret)
|
||||
@@ -78,9 +84,9 @@ class AudioContentCommentService(
|
||||
member.nickname
|
||||
},
|
||||
message = if (parent != null) {
|
||||
"댓글에 답글을 달았습니다.: ${audioContent.title}"
|
||||
formatMessage("content.comment.notification.reply", audioContent.title)
|
||||
} else {
|
||||
"콘텐츠에 댓글을 달았습니다.: ${audioContent.title}"
|
||||
formatMessage("content.comment.notification.new", audioContent.title)
|
||||
},
|
||||
contentId = audioContentId,
|
||||
commentParentId = parentId,
|
||||
@@ -105,7 +111,7 @@ class AudioContentCommentService(
|
||||
@Transactional
|
||||
fun modifyComment(request: ModifyCommentRequest, member: Member) {
|
||||
val audioContentComment = repository.findByIdOrNull(request.commentId)
|
||||
?: throw SodaException("잘못된 접근 입니다.\n확인 후 다시 시도해 주세요.")
|
||||
?: throw SodaException(messageKey = "content.comment.error.invalid_access_retry")
|
||||
|
||||
if (audioContentComment.member!!.id!! == member.id!!) {
|
||||
if (request.comment != null) {
|
||||
@@ -164,4 +170,9 @@ class AudioContentCommentService(
|
||||
|
||||
return GetAudioContentCommentListResponse(totalCount, commentList)
|
||||
}
|
||||
|
||||
private fun formatMessage(key: String, vararg args: Any): String {
|
||||
val template = messageSource.getMessage(key, langContext.lang) ?: return ""
|
||||
return String.format(template, *args)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user