AudioContent 조회 API에서 api 마다 languageCode를 별도로 받던 것을 LangContext를 사용하도록 리팩토링

This commit is contained in:
2025-12-12 19:40:21 +09:00
parent 165640201f
commit 59949e5aee
3 changed files with 33 additions and 53 deletions

View File

@@ -108,7 +108,6 @@ class AudioContentController(private val service: AudioContentService) {
@RequestParam("category-id", required = false) categoryId: Long? = 0, @RequestParam("category-id", required = false) categoryId: Long? = 0,
@RequestParam("isAdultContentVisible", required = false) isAdultContentVisible: Boolean? = null, @RequestParam("isAdultContentVisible", required = false) isAdultContentVisible: Boolean? = null,
@RequestParam("contentType", required = false) contentType: ContentType? = null, @RequestParam("contentType", required = false) contentType: ContentType? = null,
@RequestParam("languageCode", required = false) languageCode: String? = null,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?, @AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?,
pageable: Pageable pageable: Pageable
) = run { ) = run {
@@ -121,7 +120,6 @@ class AudioContentController(private val service: AudioContentService) {
categoryId = categoryId ?: 0, categoryId = categoryId ?: 0,
isAdultContentVisible = isAdultContentVisible ?: true, isAdultContentVisible = isAdultContentVisible ?: true,
contentType = contentType ?: ContentType.ALL, contentType = contentType ?: ContentType.ALL,
languageCode = languageCode,
member = member, member = member,
offset = pageable.offset, offset = pageable.offset,
limit = pageable.pageSize.toLong() limit = pageable.pageSize.toLong()
@@ -133,7 +131,6 @@ class AudioContentController(private val service: AudioContentService) {
fun getDetail( fun getDetail(
@PathVariable id: Long, @PathVariable id: Long,
@RequestParam timezone: String, @RequestParam timezone: String,
@RequestParam(required = false) languageCode: String? = null,
@RequestParam("isAdultContentVisible", required = false) isAdultContentVisible: Boolean? = null, @RequestParam("isAdultContentVisible", required = false) isAdultContentVisible: Boolean? = null,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member? @AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run { ) = run {
@@ -144,8 +141,7 @@ class AudioContentController(private val service: AudioContentService) {
id = id, id = id,
member = member, member = member,
isAdultContentVisible = isAdultContentVisible ?: true, isAdultContentVisible = isAdultContentVisible ?: true,
timezone = timezone, timezone = timezone
languageCode = languageCode
) )
) )
} }
@@ -243,7 +239,6 @@ class AudioContentController(private val service: AudioContentService) {
@GetMapping("/all") @GetMapping("/all")
fun getAllContents( fun getAllContents(
@RequestParam("languageCode", required = false) languageCode: String? = null,
@RequestParam("isAdultContentVisible", required = false) isAdultContentVisible: Boolean? = null, @RequestParam("isAdultContentVisible", required = false) isAdultContentVisible: Boolean? = null,
@RequestParam("contentType", required = false) contentType: ContentType? = null, @RequestParam("contentType", required = false) contentType: ContentType? = null,
@RequestParam("isFree", required = false) isFree: Boolean? = null, @RequestParam("isFree", required = false) isFree: Boolean? = null,
@@ -264,8 +259,7 @@ class AudioContentController(private val service: AudioContentService) {
sortType = sortType ?: SortType.NEWEST, sortType = sortType ?: SortType.NEWEST,
isFree = isFree ?: false, isFree = isFree ?: false,
isAdult = (isAdultContentVisible ?: true) && member.auth != null, isAdult = (isAdultContentVisible ?: true) && member.auth != null,
isPointAvailableOnly = isPointAvailableOnly ?: false, isPointAvailableOnly = isPointAvailableOnly ?: false
languageCode = languageCode
) )
) )
} }

View File

@@ -29,6 +29,7 @@ import kr.co.vividnext.sodalive.explorer.ExplorerQueryRepository
import kr.co.vividnext.sodalive.extensions.convertLocalDateTime import kr.co.vividnext.sodalive.extensions.convertLocalDateTime
import kr.co.vividnext.sodalive.fcm.FcmEvent import kr.co.vividnext.sodalive.fcm.FcmEvent
import kr.co.vividnext.sodalive.fcm.FcmEventType import kr.co.vividnext.sodalive.fcm.FcmEventType
import kr.co.vividnext.sodalive.i18n.LangContext
import kr.co.vividnext.sodalive.i18n.translation.LanguageTranslationEvent import kr.co.vividnext.sodalive.i18n.translation.LanguageTranslationEvent
import kr.co.vividnext.sodalive.i18n.translation.LanguageTranslationTargetType import kr.co.vividnext.sodalive.i18n.translation.LanguageTranslationTargetType
import kr.co.vividnext.sodalive.i18n.translation.PapagoTranslationService import kr.co.vividnext.sodalive.i18n.translation.PapagoTranslationService
@@ -72,6 +73,8 @@ class AudioContentService(
private val audioContentCloudFront: AudioContentCloudFront, private val audioContentCloudFront: AudioContentCloudFront,
private val applicationEventPublisher: ApplicationEventPublisher, private val applicationEventPublisher: ApplicationEventPublisher,
private val langContext: LangContext,
@Value("\${cloud.aws.s3.content-bucket}") @Value("\${cloud.aws.s3.content-bucket}")
private val audioContentBucket: String, private val audioContentBucket: String,
@@ -526,8 +529,7 @@ class AudioContentService(
id: Long, id: Long,
member: Member, member: Member,
isAdultContentVisible: Boolean, isAdultContentVisible: Boolean,
timezone: String, timezone: String
languageCode: String?
): GetAudioContentDetailResponse { ): GetAudioContentDetailResponse {
val isAdult = member.auth != null && isAdultContentVisible val isAdult = member.auth != null && isAdultContentVisible
@@ -764,13 +766,10 @@ class AudioContentService(
if ( if (
audioContent.languageCode != null && audioContent.languageCode != null &&
audioContent.languageCode!!.isNotBlank() && audioContent.languageCode!!.isNotBlank() &&
!languageCode.isNullOrBlank() && audioContent.languageCode != langContext.lang.code
audioContent.languageCode != languageCode
) { ) {
val locale = languageCode.lowercase()
val existing = contentTranslationRepository val existing = contentTranslationRepository
.findByContentIdAndLocale(audioContent.id!!, locale) .findByContentIdAndLocale(audioContent.id!!, langContext.lang.code)
if (existing != null) { if (existing != null) {
val payload = existing.renderedPayload val payload = existing.renderedPayload
@@ -791,7 +790,7 @@ class AudioContentService(
request = TranslateRequest( request = TranslateRequest(
texts = texts, texts = texts,
sourceLanguage = sourceLanguage, sourceLanguage = sourceLanguage,
targetLanguage = locale targetLanguage = langContext.lang.code
) )
) )
@@ -812,7 +811,7 @@ class AudioContentService(
contentTranslationRepository.save( contentTranslationRepository.save(
ContentTranslation( ContentTranslation(
contentId = audioContent.id!!, contentId = audioContent.id!!,
locale = locale, locale = langContext.lang.code,
renderedPayload = payload renderedPayload = payload
) )
) )
@@ -928,7 +927,6 @@ class AudioContentService(
categoryId: Long = 0, categoryId: Long = 0,
isAdultContentVisible: Boolean, isAdultContentVisible: Boolean,
contentType: ContentType, contentType: ContentType,
languageCode: String?,
offset: Long, offset: Long,
limit: Long limit: Long
): GetAudioContentListResponse { ): GetAudioContentListResponse {
@@ -982,24 +980,19 @@ class AudioContentService(
it it
} }
val translatedContentList = if (!languageCode.isNullOrBlank()) { val contentIds = items.map { it.contentId }
val contentIds = items.map { it.contentId } val translatedContentList = if (contentIds.isNotEmpty()) {
val translations = contentTranslationRepository
.findByContentIdInAndLocale(contentIds = contentIds, locale = langContext.lang.code)
.associateBy { it.contentId }
if (contentIds.isNotEmpty()) { items.map { item ->
val translations = contentTranslationRepository val translatedTitle = translations[item.contentId]?.renderedPayload?.title
.findByContentIdInAndLocale(contentIds = contentIds, locale = languageCode) if (translatedTitle.isNullOrBlank()) {
.associateBy { it.contentId } item
} else {
items.map { item -> item.copy(title = translatedTitle)
val translatedTitle = translations[item.contentId]?.renderedPayload?.title
if (translatedTitle.isNullOrBlank()) {
item
} else {
item.copy(title = translatedTitle)
}
} }
} else {
items
} }
} else { } else {
items items
@@ -1145,8 +1138,7 @@ class AudioContentService(
isFree: Boolean = false, isFree: Boolean = false,
isAdult: Boolean = false, isAdult: Boolean = false,
orderByRandom: Boolean = false, orderByRandom: Boolean = false,
isPointAvailableOnly: Boolean = false, isPointAvailableOnly: Boolean = false
languageCode: String? = null
): List<AudioContentMainItem> { ): List<AudioContentMainItem> {
val contentList = repository.getLatestContentByTheme( val contentList = repository.getLatestContentByTheme(
theme = theme, theme = theme,
@@ -1160,24 +1152,19 @@ class AudioContentService(
isPointAvailableOnly = isPointAvailableOnly isPointAvailableOnly = isPointAvailableOnly
) )
return if (!languageCode.isNullOrBlank()) { val contentIds = contentList.map { it.contentId }
val contentIds = contentList.map { it.contentId } return if (contentIds.isNotEmpty()) {
val translations = contentTranslationRepository
.findByContentIdInAndLocale(contentIds = contentIds, locale = langContext.lang.code)
.associateBy { it.contentId }
if (contentIds.isNotEmpty()) { contentList.map { item ->
val translations = contentTranslationRepository val translatedTitle = translations[item.contentId]?.renderedPayload?.title
.findByContentIdInAndLocale(contentIds = contentIds, locale = languageCode) if (translatedTitle.isNullOrBlank()) {
.associateBy { it.contentId } item
} else {
contentList.map { item -> item.copy(title = translatedTitle)
val translatedTitle = translations[item.contentId]?.renderedPayload?.title
if (translatedTitle.isNullOrBlank()) {
item
} else {
item.copy(title = translatedTitle)
}
} }
} else {
contentList
} }
} else { } else {
contentList contentList

View File

@@ -227,7 +227,6 @@ class ExplorerService(
sortType = SortType.NEWEST, sortType = SortType.NEWEST,
isAdultContentVisible = isAdultContentVisible, isAdultContentVisible = isAdultContentVisible,
contentType = ContentType.ALL, contentType = ContentType.ALL,
languageCode = null,
member = member, member = member,
offset = 0, offset = 0,
limit = 3 limit = 3