feat(content): 오디오 업로드 최근 소식을 발행한다
This commit is contained in:
@@ -39,6 +39,7 @@ import kr.co.vividnext.sodalive.member.Member
|
||||
import kr.co.vividnext.sodalive.member.block.BlockMemberRepository
|
||||
import kr.co.vividnext.sodalive.member.contentpreference.isAdultVisibleByPolicy
|
||||
import kr.co.vividnext.sodalive.utils.generateFileName
|
||||
import kr.co.vividnext.sodalive.v2.home.following.application.HomeFollowingNewsPublishService
|
||||
import kr.co.vividnext.sodalive.v2.recommendation.application.CreatorContentViewHistoryService
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
@@ -47,6 +48,8 @@ import org.springframework.context.ApplicationEventPublisher
|
||||
import org.springframework.data.repository.findByIdOrNull
|
||||
import org.springframework.stereotype.Service
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
import org.springframework.transaction.support.TransactionSynchronization
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager
|
||||
import org.springframework.web.multipart.MultipartFile
|
||||
import java.text.SimpleDateFormat
|
||||
import java.time.LocalDateTime
|
||||
@@ -82,6 +85,7 @@ class AudioContentService(
|
||||
private val langContext: LangContext,
|
||||
|
||||
private val contentThemeTranslationRepository: ContentThemeTranslationRepository,
|
||||
private val homeFollowingNewsPublishService: HomeFollowingNewsPublishService,
|
||||
|
||||
@Value("\${cloud.aws.s3.content-bucket}")
|
||||
private val audioContentBucket: String,
|
||||
@@ -476,7 +480,8 @@ class AudioContentService(
|
||||
)
|
||||
)
|
||||
|
||||
if (audioContent.releaseDate == null || audioContent.releaseDate!! <= audioContent.createdAt) {
|
||||
val now = LocalDateTime.now()
|
||||
if (audioContent.releaseDate == null || audioContent.releaseDate!! <= now) {
|
||||
audioContent.isActive = true
|
||||
|
||||
applicationEventPublisher.publishEvent(
|
||||
@@ -494,6 +499,10 @@ class AudioContentService(
|
||||
deepLinkId = contentId
|
||||
)
|
||||
)
|
||||
publishContentUploadedAfterCommit(
|
||||
audioContent = audioContent,
|
||||
visibleFromAtUtc = audioContent.releaseDate ?: audioContent.createdAt ?: now
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -520,9 +529,64 @@ class AudioContentService(
|
||||
deepLinkId = audioContent.id!!
|
||||
)
|
||||
)
|
||||
publishContentUploadedAfterCommit(
|
||||
audioContent = audioContent,
|
||||
visibleFromAtUtc = audioContent.releaseDate ?: LocalDateTime.now()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun publishContentUploadedAfterCommit(audioContent: AudioContent, visibleFromAtUtc: LocalDateTime) {
|
||||
val creator = audioContent.member!!
|
||||
val occurredAtUtc = audioContent.createdAt ?: visibleFromAtUtc
|
||||
val newsBody = audioContent.newsDetailPreview()
|
||||
afterCommit {
|
||||
homeFollowingNewsPublishService.publishContentUploaded(
|
||||
contentId = audioContent.id!!,
|
||||
creatorId = creator.id!!,
|
||||
creatorNickname = creator.nickname,
|
||||
creatorProfileImagePath = creator.profileImage,
|
||||
title = audioContent.title,
|
||||
body = newsBody,
|
||||
thumbnailImagePath = audioContent.coverImage,
|
||||
occurredAtUtc = occurredAtUtc,
|
||||
visibleFromAtUtc = visibleFromAtUtc,
|
||||
isAdult = audioContent.isAdult
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun AudioContent.newsDetailPreview(): String {
|
||||
if (price < 50 || isFullDetailVisible) {
|
||||
return detail
|
||||
}
|
||||
|
||||
val length = detail.length
|
||||
return if (length < 60) {
|
||||
"${detail.take(length / 2)}..."
|
||||
} else {
|
||||
"${detail.take(30)}..."
|
||||
}
|
||||
}
|
||||
|
||||
private fun afterCommit(action: () -> Unit) {
|
||||
if (!TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||
runCatching(action).onFailure { ex ->
|
||||
log.warn("event=home_following_news_publish_failure error={}", ex.message, ex)
|
||||
}
|
||||
return
|
||||
}
|
||||
TransactionSynchronizationManager.registerSynchronization(
|
||||
object : TransactionSynchronization {
|
||||
override fun afterCommit() {
|
||||
runCatching(action).onFailure { ex ->
|
||||
log.warn("event=home_following_news_publish_failure error={}", ex.message, ex)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Transactional
|
||||
fun getDetail(
|
||||
id: Long,
|
||||
|
||||
Reference in New Issue
Block a user