AudioContent 조회 API에서 api 마다 languageCode를 별도로 받던 것을 LangContext를 사용하도록 리팩토링
This commit is contained in:
@@ -108,7 +108,6 @@ class AudioContentController(private val service: AudioContentService) {
|
||||
@RequestParam("category-id", required = false) categoryId: Long? = 0,
|
||||
@RequestParam("isAdultContentVisible", required = false) isAdultContentVisible: Boolean? = null,
|
||||
@RequestParam("contentType", required = false) contentType: ContentType? = null,
|
||||
@RequestParam("languageCode", required = false) languageCode: String? = null,
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?,
|
||||
pageable: Pageable
|
||||
) = run {
|
||||
@@ -121,7 +120,6 @@ class AudioContentController(private val service: AudioContentService) {
|
||||
categoryId = categoryId ?: 0,
|
||||
isAdultContentVisible = isAdultContentVisible ?: true,
|
||||
contentType = contentType ?: ContentType.ALL,
|
||||
languageCode = languageCode,
|
||||
member = member,
|
||||
offset = pageable.offset,
|
||||
limit = pageable.pageSize.toLong()
|
||||
@@ -133,7 +131,6 @@ class AudioContentController(private val service: AudioContentService) {
|
||||
fun getDetail(
|
||||
@PathVariable id: Long,
|
||||
@RequestParam timezone: String,
|
||||
@RequestParam(required = false) languageCode: String? = null,
|
||||
@RequestParam("isAdultContentVisible", required = false) isAdultContentVisible: Boolean? = null,
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
||||
) = run {
|
||||
@@ -144,8 +141,7 @@ class AudioContentController(private val service: AudioContentService) {
|
||||
id = id,
|
||||
member = member,
|
||||
isAdultContentVisible = isAdultContentVisible ?: true,
|
||||
timezone = timezone,
|
||||
languageCode = languageCode
|
||||
timezone = timezone
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -243,7 +239,6 @@ class AudioContentController(private val service: AudioContentService) {
|
||||
|
||||
@GetMapping("/all")
|
||||
fun getAllContents(
|
||||
@RequestParam("languageCode", required = false) languageCode: String? = null,
|
||||
@RequestParam("isAdultContentVisible", required = false) isAdultContentVisible: Boolean? = null,
|
||||
@RequestParam("contentType", required = false) contentType: ContentType? = null,
|
||||
@RequestParam("isFree", required = false) isFree: Boolean? = null,
|
||||
@@ -264,8 +259,7 @@ class AudioContentController(private val service: AudioContentService) {
|
||||
sortType = sortType ?: SortType.NEWEST,
|
||||
isFree = isFree ?: false,
|
||||
isAdult = (isAdultContentVisible ?: true) && member.auth != null,
|
||||
isPointAvailableOnly = isPointAvailableOnly ?: false,
|
||||
languageCode = languageCode
|
||||
isPointAvailableOnly = isPointAvailableOnly ?: false
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import kr.co.vividnext.sodalive.explorer.ExplorerQueryRepository
|
||||
import kr.co.vividnext.sodalive.extensions.convertLocalDateTime
|
||||
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.translation.LanguageTranslationEvent
|
||||
import kr.co.vividnext.sodalive.i18n.translation.LanguageTranslationTargetType
|
||||
import kr.co.vividnext.sodalive.i18n.translation.PapagoTranslationService
|
||||
@@ -72,6 +73,8 @@ class AudioContentService(
|
||||
private val audioContentCloudFront: AudioContentCloudFront,
|
||||
private val applicationEventPublisher: ApplicationEventPublisher,
|
||||
|
||||
private val langContext: LangContext,
|
||||
|
||||
@Value("\${cloud.aws.s3.content-bucket}")
|
||||
private val audioContentBucket: String,
|
||||
|
||||
@@ -526,8 +529,7 @@ class AudioContentService(
|
||||
id: Long,
|
||||
member: Member,
|
||||
isAdultContentVisible: Boolean,
|
||||
timezone: String,
|
||||
languageCode: String?
|
||||
timezone: String
|
||||
): GetAudioContentDetailResponse {
|
||||
val isAdult = member.auth != null && isAdultContentVisible
|
||||
|
||||
@@ -764,13 +766,10 @@ class AudioContentService(
|
||||
if (
|
||||
audioContent.languageCode != null &&
|
||||
audioContent.languageCode!!.isNotBlank() &&
|
||||
!languageCode.isNullOrBlank() &&
|
||||
audioContent.languageCode != languageCode
|
||||
audioContent.languageCode != langContext.lang.code
|
||||
) {
|
||||
val locale = languageCode.lowercase()
|
||||
|
||||
val existing = contentTranslationRepository
|
||||
.findByContentIdAndLocale(audioContent.id!!, locale)
|
||||
.findByContentIdAndLocale(audioContent.id!!, langContext.lang.code)
|
||||
|
||||
if (existing != null) {
|
||||
val payload = existing.renderedPayload
|
||||
@@ -791,7 +790,7 @@ class AudioContentService(
|
||||
request = TranslateRequest(
|
||||
texts = texts,
|
||||
sourceLanguage = sourceLanguage,
|
||||
targetLanguage = locale
|
||||
targetLanguage = langContext.lang.code
|
||||
)
|
||||
)
|
||||
|
||||
@@ -812,7 +811,7 @@ class AudioContentService(
|
||||
contentTranslationRepository.save(
|
||||
ContentTranslation(
|
||||
contentId = audioContent.id!!,
|
||||
locale = locale,
|
||||
locale = langContext.lang.code,
|
||||
renderedPayload = payload
|
||||
)
|
||||
)
|
||||
@@ -928,7 +927,6 @@ class AudioContentService(
|
||||
categoryId: Long = 0,
|
||||
isAdultContentVisible: Boolean,
|
||||
contentType: ContentType,
|
||||
languageCode: String?,
|
||||
offset: Long,
|
||||
limit: Long
|
||||
): GetAudioContentListResponse {
|
||||
@@ -982,24 +980,19 @@ class AudioContentService(
|
||||
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()) {
|
||||
val translations = contentTranslationRepository
|
||||
.findByContentIdInAndLocale(contentIds = contentIds, locale = languageCode)
|
||||
.associateBy { it.contentId }
|
||||
|
||||
items.map { item ->
|
||||
val translatedTitle = translations[item.contentId]?.renderedPayload?.title
|
||||
if (translatedTitle.isNullOrBlank()) {
|
||||
item
|
||||
} else {
|
||||
item.copy(title = translatedTitle)
|
||||
}
|
||||
items.map { item ->
|
||||
val translatedTitle = translations[item.contentId]?.renderedPayload?.title
|
||||
if (translatedTitle.isNullOrBlank()) {
|
||||
item
|
||||
} else {
|
||||
item.copy(title = translatedTitle)
|
||||
}
|
||||
} else {
|
||||
items
|
||||
}
|
||||
} else {
|
||||
items
|
||||
@@ -1145,8 +1138,7 @@ class AudioContentService(
|
||||
isFree: Boolean = false,
|
||||
isAdult: Boolean = false,
|
||||
orderByRandom: Boolean = false,
|
||||
isPointAvailableOnly: Boolean = false,
|
||||
languageCode: String? = null
|
||||
isPointAvailableOnly: Boolean = false
|
||||
): List<AudioContentMainItem> {
|
||||
val contentList = repository.getLatestContentByTheme(
|
||||
theme = theme,
|
||||
@@ -1160,24 +1152,19 @@ class AudioContentService(
|
||||
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()) {
|
||||
val translations = contentTranslationRepository
|
||||
.findByContentIdInAndLocale(contentIds = contentIds, locale = languageCode)
|
||||
.associateBy { it.contentId }
|
||||
|
||||
contentList.map { item ->
|
||||
val translatedTitle = translations[item.contentId]?.renderedPayload?.title
|
||||
if (translatedTitle.isNullOrBlank()) {
|
||||
item
|
||||
} else {
|
||||
item.copy(title = translatedTitle)
|
||||
}
|
||||
contentList.map { item ->
|
||||
val translatedTitle = translations[item.contentId]?.renderedPayload?.title
|
||||
if (translatedTitle.isNullOrBlank()) {
|
||||
item
|
||||
} else {
|
||||
item.copy(title = translatedTitle)
|
||||
}
|
||||
} else {
|
||||
contentList
|
||||
}
|
||||
} else {
|
||||
contentList
|
||||
|
||||
@@ -227,7 +227,6 @@ class ExplorerService(
|
||||
sortType = SortType.NEWEST,
|
||||
isAdultContentVisible = isAdultContentVisible,
|
||||
contentType = ContentType.ALL,
|
||||
languageCode = null,
|
||||
member = member,
|
||||
offset = 0,
|
||||
limit = 3
|
||||
|
||||
Reference in New Issue
Block a user