fix(content): 상세 연관 콘텐츠에 요청 언어의 저장된 제목을 적용한다
This commit is contained in:
@@ -800,6 +800,24 @@ class AudioContentService(
|
|||||||
isAdult = isAdult
|
isAdult = isAdult
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val relatedContentIds = listOfNotNull(previousContent, nextContent)
|
||||||
|
.plus(creatorOtherContentList)
|
||||||
|
.plus(sameThemeOtherContentList)
|
||||||
|
.map { it.contentId }
|
||||||
|
.distinct()
|
||||||
|
val relatedTranslations = if (relatedContentIds.isNotEmpty()) {
|
||||||
|
contentTranslationRepository
|
||||||
|
.findByContentIdInAndLocale(contentIds = relatedContentIds, locale = langContext.lang.code)
|
||||||
|
.associateBy { it.contentId }
|
||||||
|
} else {
|
||||||
|
emptyMap()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun translateRelatedContent(item: OtherContentResponse): OtherContentResponse {
|
||||||
|
val translatedTitle = relatedTranslations[item.contentId]?.renderedPayload?.title
|
||||||
|
return if (translatedTitle.isNullOrBlank()) item else item.copy(title = translatedTitle)
|
||||||
|
}
|
||||||
|
|
||||||
val likeCount = audioContentLikeRepository.totalCountAudioContentLike(contentId = id)
|
val likeCount = audioContentLikeRepository.totalCountAudioContentLike(contentId = id)
|
||||||
val isLike = audioContentLikeRepository.findByMemberIdAndContentId(
|
val isLike = audioContentLikeRepository.findByMemberIdAndContentId(
|
||||||
memberId = member.id!!,
|
memberId = member.id!!,
|
||||||
@@ -942,8 +960,8 @@ class AudioContentService(
|
|||||||
purchaseOption = purchaseOption,
|
purchaseOption = purchaseOption,
|
||||||
orderType = orderType,
|
orderType = orderType,
|
||||||
remainingTime = remainingTime,
|
remainingTime = remainingTime,
|
||||||
creatorOtherContentList = creatorOtherContentList,
|
creatorOtherContentList = creatorOtherContentList.map(::translateRelatedContent),
|
||||||
sameThemeOtherContentList = sameThemeOtherContentList,
|
sameThemeOtherContentList = sameThemeOtherContentList.map(::translateRelatedContent),
|
||||||
isCommentAvailable = audioContent.isCommentAvailable,
|
isCommentAvailable = audioContent.isCommentAvailable,
|
||||||
isLike = isLike,
|
isLike = isLike,
|
||||||
likeCount = likeCount,
|
likeCount = likeCount,
|
||||||
@@ -963,8 +981,8 @@ class AudioContentService(
|
|||||||
isFollow = creatorFollowing?.isFollow ?: false,
|
isFollow = creatorFollowing?.isFollow ?: false,
|
||||||
isNotify = creatorFollowing?.isNotify ?: false
|
isNotify = creatorFollowing?.isNotify ?: false
|
||||||
),
|
),
|
||||||
previousContent = previousContent,
|
previousContent = previousContent?.let(::translateRelatedContent),
|
||||||
nextContent = nextContent,
|
nextContent = nextContent?.let(::translateRelatedContent),
|
||||||
buyerList = buyerList,
|
buyerList = buyerList,
|
||||||
isAvailableUsePoint = audioContent.isPointAvailable && audioContent.price > 0,
|
isAvailableUsePoint = audioContent.isPointAvailable && audioContent.price > 0,
|
||||||
translated = translation.translated,
|
translated = translation.translated,
|
||||||
|
|||||||
+157
-3
@@ -2,10 +2,15 @@ package kr.co.vividnext.sodalive.content
|
|||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode
|
import com.fasterxml.jackson.databind.JsonNode
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
|
import kr.co.vividnext.sodalive.admin.content.series.genre.SeriesGenre
|
||||||
import kr.co.vividnext.sodalive.content.hashtag.AudioContentHashTag
|
import kr.co.vividnext.sodalive.content.hashtag.AudioContentHashTag
|
||||||
import kr.co.vividnext.sodalive.content.hashtag.HashTag
|
import kr.co.vividnext.sodalive.content.hashtag.HashTag
|
||||||
import kr.co.vividnext.sodalive.content.theme.AudioContentTheme
|
import kr.co.vividnext.sodalive.content.theme.AudioContentTheme
|
||||||
|
import kr.co.vividnext.sodalive.content.translation.ContentTranslation
|
||||||
|
import kr.co.vividnext.sodalive.content.translation.ContentTranslationPayload
|
||||||
import kr.co.vividnext.sodalive.content.translation.ContentTranslationRepository
|
import kr.co.vividnext.sodalive.content.translation.ContentTranslationRepository
|
||||||
|
import kr.co.vividnext.sodalive.creator.admin.content.series.Series
|
||||||
|
import kr.co.vividnext.sodalive.creator.admin.content.series.SeriesContent
|
||||||
import kr.co.vividnext.sodalive.i18n.translation.LanguageTranslationTargetType
|
import kr.co.vividnext.sodalive.i18n.translation.LanguageTranslationTargetType
|
||||||
import kr.co.vividnext.sodalive.i18n.translation.ResourceTranslationJobScheduler
|
import kr.co.vividnext.sodalive.i18n.translation.ResourceTranslationJobScheduler
|
||||||
import kr.co.vividnext.sodalive.i18n.translation.SourceTextNormalizer
|
import kr.co.vividnext.sodalive.i18n.translation.SourceTextNormalizer
|
||||||
@@ -48,7 +53,10 @@ import javax.persistence.EntityManager
|
|||||||
@SpringBootTest(
|
@SpringBootTest(
|
||||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||||
classes = [ContentDetailTranslationTestConfiguration::class],
|
classes = [ContentDetailTranslationTestConfiguration::class],
|
||||||
properties = ["spring.cache.type=none", "spring.jpa.properties.hibernate.show_sql=false"]
|
properties = [
|
||||||
|
"spring.cache.type=none", "spring.jpa.properties.hibernate.show_sql=false",
|
||||||
|
"cloud.aws.cloud-front.host=https://cdn.test"
|
||||||
|
]
|
||||||
)
|
)
|
||||||
@ActiveProfiles("content-detail-translation-test")
|
@ActiveProfiles("content-detail-translation-test")
|
||||||
class AudioContentDetailTranslationHttpIntegrationTest @Autowired constructor(
|
class AudioContentDetailTranslationHttpIntegrationTest @Autowired constructor(
|
||||||
@@ -74,6 +82,9 @@ class AudioContentDetailTranslationHttpIntegrationTest @Autowired constructor(
|
|||||||
@SpyBean
|
@SpyBean
|
||||||
private lateinit var jobClaims: TranslationJobRepository
|
private lateinit var jobClaims: TranslationJobRepository
|
||||||
|
|
||||||
|
@SpyBean
|
||||||
|
private lateinit var translationReads: ContentTranslationRepository
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
fun prepare() {
|
fun prepare() {
|
||||||
provider.reset()
|
provider.reset()
|
||||||
@@ -337,11 +348,154 @@ class AudioContentDetailTranslationHttpIntegrationTest @Autowired constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun detail(fixture: Pair<Long, Long>): JsonNode {
|
@Test
|
||||||
|
@DisplayName("연관 콘텐츠 네 필드는 en-ja-en 요청 언어의 저장 제목만 적용하고 원문 탐색을 유지한다")
|
||||||
|
fun shouldLocalizeRelatedTitlesForEachRequestedLanguageWithoutChangingNavigation() {
|
||||||
|
val fixture = fixture()
|
||||||
|
val related = relatedFixture(fixture)
|
||||||
|
translations.saveAllAndFlush(
|
||||||
|
related.flatMap { item ->
|
||||||
|
listOf("en", "ja").map { locale ->
|
||||||
|
ContentTranslation(item.contentId, locale, ContentTranslationPayload("$locale ${item.title}", "", ""))
|
||||||
|
}
|
||||||
|
} + ContentTranslation(
|
||||||
|
fixture.first,
|
||||||
|
"ja",
|
||||||
|
ContentTranslationPayload("Japanese title", "Japanese detail", "#Japanese")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
listOf("en", "ja", "en").forEach { locale ->
|
||||||
|
Mockito.clearInvocations(translationReads)
|
||||||
|
val response = detail(fixture, locale)
|
||||||
|
|
||||||
|
assertRelatedContent(response, related.map { it.copy(title = "$locale ${it.title}") })
|
||||||
|
assertTranslation(
|
||||||
|
response,
|
||||||
|
if (locale == "en") "English title" else "Japanese title",
|
||||||
|
if (locale == "en") "English detail" else "Japanese detail",
|
||||||
|
if (locale == "en") "#Healing" else "#Japanese"
|
||||||
|
)
|
||||||
|
val batches = Mockito.mockingDetails(translationReads).invocations
|
||||||
|
.filter { it.method.name == "findByContentIdInAndLocale" }
|
||||||
|
assertEquals(1, batches.size)
|
||||||
|
val ids = batches.single().getArgument<List<Long>>(0)
|
||||||
|
assertEquals(related.size, ids.size)
|
||||||
|
assertEquals(related.map { it.contentId }.toSet(), ids.toSet())
|
||||||
|
assertEquals(locale, batches.single().getArgument<String>(1))
|
||||||
|
assertEquals(3, provider.calls.get())
|
||||||
|
assertEquals(0L, jobs.count())
|
||||||
|
assertEquals(related.size * 2 + 2L, translations.count())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@NullAndEmptySource
|
||||||
|
@ValueSource(strings = [" \t ", "Japanese only"])
|
||||||
|
@DisplayName("연관 제목은 요청 언어 번역 없음 또는 빈 값이면 다른 언어 대신 원문을 유지한다")
|
||||||
|
fun shouldKeepOriginalRelatedTitlesWhenRequestedTranslationIsMissingOrBlank(title: String?) {
|
||||||
|
val fixture = fixture()
|
||||||
|
val related = relatedFixture(fixture)
|
||||||
|
if (title != null) {
|
||||||
|
translations.saveAllAndFlush(
|
||||||
|
related.map {
|
||||||
|
ContentTranslation(
|
||||||
|
it.contentId,
|
||||||
|
if (title == "Japanese only") "ja" else "en",
|
||||||
|
ContentTranslationPayload(title, "", "")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val response = detail(fixture, "en")
|
||||||
|
|
||||||
|
assertRelatedContent(response, related)
|
||||||
|
assertTranslation(response, "English title", "English detail", "#Healing")
|
||||||
|
assertEquals(3, provider.calls.get())
|
||||||
|
assertEquals(0L, jobs.count())
|
||||||
|
assertEquals(if (title == null) 1L else related.size + 1L, translations.count())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("연관 콘텐츠가 없으면 이전 다음은 null이고 추천은 빈 목록이며 배치 조회를 생략한다")
|
||||||
|
fun shouldKeepNullNeighborsAndEmptyRecommendationsWithoutTranslationLookup() {
|
||||||
|
val fixture = fixture()
|
||||||
|
Mockito.clearInvocations(translationReads)
|
||||||
|
|
||||||
|
val response = detail(fixture)
|
||||||
|
|
||||||
|
assertTrue(response.path("previousContent").isNull)
|
||||||
|
assertTrue(response.path("nextContent").isNull)
|
||||||
|
assertEquals(emptyList<JsonNode>(), response.path("creatorOtherContentList").toList())
|
||||||
|
assertEquals(emptyList<JsonNode>(), response.path("sameThemeOtherContentList").toList())
|
||||||
|
assertEquals(
|
||||||
|
0,
|
||||||
|
Mockito.mockingDetails(translationReads).invocations.count { it.method.name == "findByContentIdInAndLocale" }
|
||||||
|
)
|
||||||
|
assertTranslation(response, "English title", "English detail", "#Healing")
|
||||||
|
assertEquals(3, provider.calls.get())
|
||||||
|
assertEquals(0L, jobs.count())
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertRelatedContent(response: JsonNode, expected: List<OtherContentResponse>) {
|
||||||
|
assertEquals(expected[0], mapper.treeToValue(response.path("previousContent"), OtherContentResponse::class.java))
|
||||||
|
assertEquals(expected[1], mapper.treeToValue(response.path("nextContent"), OtherContentResponse::class.java))
|
||||||
|
listOf("creatorOtherContentList" to listOf(0, 1, 2), "sameThemeOtherContentList" to listOf(0, 1, 3))
|
||||||
|
.forEach { (field, indices) ->
|
||||||
|
val actual = response.path(field).map { mapper.treeToValue(it, OtherContentResponse::class.java) }
|
||||||
|
assertEquals(indices.size, actual.size)
|
||||||
|
assertEquals(indices.map { expected[it] }.associateBy { it.contentId }, actual.associateBy { it.contentId })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun relatedFixture(fixture: Pair<Long, Long>): List<OtherContentResponse> = transaction.execute {
|
||||||
|
val current = entityManager.find(AudioContent::class.java, fixture.first)
|
||||||
|
current.releaseDate = LocalDateTime.of(2020, 1, 1, 0, 0)
|
||||||
|
val genre = SeriesGenre("related-genre")
|
||||||
|
val series = Series("related-series", "related-introduction", "ko").apply {
|
||||||
|
member = current.member
|
||||||
|
this.genre = genre
|
||||||
|
}
|
||||||
|
val otherCreator = Member(password = "test", nickname = "other-creator", role = MemberRole.CREATOR)
|
||||||
|
val otherTheme = AudioContentTheme("other-theme", "other-theme.png")
|
||||||
|
listOf(genre, series, otherCreator, otherTheme).forEach(entityManager::persist)
|
||||||
|
entityManager.persist(
|
||||||
|
SeriesContent().apply {
|
||||||
|
this.series = series
|
||||||
|
content = current
|
||||||
|
}
|
||||||
|
)
|
||||||
|
listOf("가 이전", "하 다음", "creator only", "theme only").mapIndexed { index, title ->
|
||||||
|
val content = AudioContent(title, "related detail", "ko", releaseDate = current.releaseDate).apply {
|
||||||
|
member = if (index == 3) otherCreator else current.member
|
||||||
|
theme = if (index == 2) otherTheme else current.theme
|
||||||
|
coverImage = "related-$index.png"
|
||||||
|
isActive = true
|
||||||
|
}
|
||||||
|
entityManager.persist(content)
|
||||||
|
if (index < 2) {
|
||||||
|
entityManager.persist(
|
||||||
|
SeriesContent().apply {
|
||||||
|
this.series = series
|
||||||
|
this.content = content
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
OtherContentResponse(requireNotNull(content.id), title, "https://cdn.test/related-$index.png")
|
||||||
|
}
|
||||||
|
}!!
|
||||||
|
|
||||||
|
private fun detail(fixture: Pair<Long, Long>, locale: String? = null): JsonNode {
|
||||||
val response = http.exchange(
|
val response = http.exchange(
|
||||||
"/audio-content/${fixture.first}?timezone=UTC",
|
"/audio-content/${fixture.first}?timezone=UTC",
|
||||||
HttpMethod.GET,
|
HttpMethod.GET,
|
||||||
HttpEntity<Void>(HttpHeaders().apply { set("X-Test-Member", fixture.second.toString()) }),
|
HttpEntity<Void>(
|
||||||
|
HttpHeaders().apply {
|
||||||
|
set("X-Test-Member", fixture.second.toString())
|
||||||
|
if (locale != null) set("Accept-Language", locale)
|
||||||
|
}
|
||||||
|
),
|
||||||
String::class.java
|
String::class.java
|
||||||
)
|
)
|
||||||
assertEquals(200, response.statusCodeValue, response.body)
|
assertEquals(200, response.statusCodeValue, response.body)
|
||||||
|
|||||||
+1
-1
@@ -102,7 +102,7 @@ class ContentDetailTranslationTestConfiguration : WebMvcConfigurer {
|
|||||||
val principal = MemberAdapter(members.findById(request.getHeader("X-Test-Member").toLong()).orElseThrow())
|
val principal = MemberAdapter(members.findById(request.getHeader("X-Test-Member").toLong()).orElseThrow())
|
||||||
SecurityContextHolder.getContext().authentication =
|
SecurityContextHolder.getContext().authentication =
|
||||||
UsernamePasswordAuthenticationToken(principal, null, principal.authorities)
|
UsernamePasswordAuthenticationToken(principal, null, principal.authorities)
|
||||||
lang.setLang(Lang.EN)
|
lang.setLang(Lang.fromAcceptLanguage(request.getHeader("Accept-Language") ?: "en"))
|
||||||
try {
|
try {
|
||||||
chain.doFilter(request, response)
|
chain.doFilter(request, response)
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user