feat(creator-channel): 커뮤니티 조회에 본문 번역을 적용한다
This commit is contained in:
+23
-4
@@ -21,6 +21,7 @@ import kr.co.vividnext.sodalive.v2.creator.channel.community.port.out.CreatorCha
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.community.port.out.CreatorChannelCommunityCreatorRecord
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.community.port.out.CreatorChannelCommunityPostRecord
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.community.port.out.CreatorChannelCommunityQueryPort
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.community.translation.application.CreatorCommunityTranslationService
|
||||
import org.springframework.beans.factory.ObjectProvider
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.stereotype.Service
|
||||
@@ -36,6 +37,7 @@ class CreatorChannelCommunityQueryService(
|
||||
private val audioContentCloudFront: AudioContentCloudFront,
|
||||
private val messageSource: SodaMessageSource,
|
||||
private val langContext: LangContext,
|
||||
private val creatorCommunityTranslationService: CreatorCommunityTranslationService,
|
||||
@Value("\${cloud.aws.cloud-front.host}")
|
||||
private val cloudFrontHost: String
|
||||
) {
|
||||
@@ -69,6 +71,9 @@ class CreatorChannelCommunityQueryService(
|
||||
offset = communityPage.offset,
|
||||
limit = communityPage.fetchLimit
|
||||
)
|
||||
val communityPosts = queryPolicy.limitItems(fetchedPosts, communityPage)
|
||||
val displayContents = creatorCommunityTranslationService
|
||||
.findDisplayContents(communityPosts.map { it.postId }, langContext.lang.code)
|
||||
|
||||
return CreatorChannelCommunityTab(
|
||||
communityPostCount = queryPort.countCommunityPosts(
|
||||
@@ -76,7 +81,9 @@ class CreatorChannelCommunityQueryService(
|
||||
viewerId = viewerId,
|
||||
canViewAdultContent = canViewAdultContent
|
||||
),
|
||||
communityPosts = queryPolicy.limitItems(fetchedPosts, communityPage).map { it.toDomain(viewerId) },
|
||||
communityPosts = communityPosts.map {
|
||||
it.copy(content = displayContents[it.postId]?.content ?: it.content).toDomain(viewerId)
|
||||
},
|
||||
page = communityPage,
|
||||
hasNext = queryPolicy.hasNext(fetchedPosts, communityPage)
|
||||
)
|
||||
@@ -89,7 +96,7 @@ class CreatorChannelCommunityQueryService(
|
||||
canViewAdultContent: Boolean,
|
||||
limit: Int
|
||||
): List<CreatorChannelCommunityPost> {
|
||||
return queryPortProvider.getObject()
|
||||
val posts = queryPortProvider.getObject()
|
||||
.findHomeCommunityPosts(
|
||||
creatorId = creatorId,
|
||||
viewerId = viewerId,
|
||||
@@ -97,7 +104,12 @@ class CreatorChannelCommunityQueryService(
|
||||
canViewAdultContent = canViewAdultContent,
|
||||
limit = limit
|
||||
)
|
||||
.map { it.toDomain(viewerId) }
|
||||
val displayContents = creatorCommunityTranslationService
|
||||
.findDisplayContents(posts.map { it.postId }, langContext.lang.code)
|
||||
|
||||
return posts.map {
|
||||
it.copy(content = displayContents[it.postId]?.content ?: it.content).toDomain(viewerId)
|
||||
}
|
||||
}
|
||||
|
||||
fun getCommunityPostDetail(
|
||||
@@ -113,8 +125,15 @@ class CreatorChannelCommunityQueryService(
|
||||
|
||||
validateNotBlocked(queryPort, viewerId, postRecord.creatorId)
|
||||
|
||||
val locale = langContext.lang.code
|
||||
val displayContent = creatorCommunityTranslationService
|
||||
.findDisplayContents(listOf(postRecord.postId), locale)[postRecord.postId]
|
||||
if (displayContent?.hasValidTranslation != true) {
|
||||
creatorCommunityTranslationService.requestTranslations(postRecord.postId, locale)
|
||||
}
|
||||
|
||||
return CreatorChannelCommunityPostDetail(
|
||||
post = postRecord.toDomain(viewerId),
|
||||
post = postRecord.copy(content = displayContent?.content ?: postRecord.content).toDomain(viewerId),
|
||||
comments = getCommunityComments(postId, viewer, page = 0, size = 20, now = now)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user