feat(community): 커뮤니티 게시글 최근 소식을 발행한다
This commit is contained in:
@@ -27,11 +27,15 @@ import kr.co.vividnext.sodalive.member.Member
|
||||
import kr.co.vividnext.sodalive.member.block.BlockMemberRepository
|
||||
import kr.co.vividnext.sodalive.utils.generateFileName
|
||||
import kr.co.vividnext.sodalive.utils.validateImage
|
||||
import kr.co.vividnext.sodalive.v2.home.following.application.HomeFollowingNewsPublishService
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
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.time.LocalDateTime
|
||||
import java.time.ZoneId
|
||||
@@ -52,6 +56,7 @@ class CreatorCommunityService(
|
||||
private val applicationEventPublisher: ApplicationEventPublisher,
|
||||
private val messageSource: SodaMessageSource,
|
||||
private val langContext: LangContext,
|
||||
private val homeFollowingNewsPublishService: HomeFollowingNewsPublishService,
|
||||
|
||||
@Value("\${cloud.aws.s3.bucket}")
|
||||
private val imageBucket: String,
|
||||
@@ -62,6 +67,8 @@ class CreatorCommunityService(
|
||||
@Value("\${cloud.aws.cloud-front.host}")
|
||||
private val imageHost: String
|
||||
) {
|
||||
private val log = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
@Transactional
|
||||
fun createCommunityPost(
|
||||
audioFile: MultipartFile?,
|
||||
@@ -134,6 +141,54 @@ class CreatorCommunityService(
|
||||
deepLinkId = member.id!!
|
||||
)
|
||||
)
|
||||
publishCommunityPostCreatedAfterCommit(post, member)
|
||||
}
|
||||
|
||||
private fun publishCommunityPostCreatedAfterCommit(post: CreatorCommunity, member: Member) {
|
||||
val occurredAtUtc = post.createdAt ?: LocalDateTime.now()
|
||||
val newsContent = post.newsContentPreview()
|
||||
afterCommit {
|
||||
homeFollowingNewsPublishService.publishCommunityPostCreated(
|
||||
postId = post.id!!,
|
||||
creatorId = member.id!!,
|
||||
creatorNickname = member.nickname,
|
||||
creatorProfileImagePath = member.profileImage,
|
||||
title = newsContent.take(80),
|
||||
body = newsContent,
|
||||
thumbnailImagePath = post.imagePath,
|
||||
occurredAtUtc = occurredAtUtc,
|
||||
isAdult = post.isAdult
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun CreatorCommunity.newsContentPreview(): String {
|
||||
if (price <= 0) {
|
||||
return content
|
||||
}
|
||||
|
||||
val length = content.codePointCount(0, content.length)
|
||||
val previewLength = if (length > 15) 15 else length / 2
|
||||
val endIndex = content.offsetByCodePoints(0, previewLength)
|
||||
return content.substring(0, endIndex).plus("...")
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user