feat(channel-donation): 채널 후원 기능 추가
This commit is contained in:
@@ -5,6 +5,7 @@ import kr.co.vividnext.sodalive.can.payment.PaymentGateway
|
||||
import kr.co.vividnext.sodalive.can.use.CanUsage
|
||||
import kr.co.vividnext.sodalive.common.CountryContext
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import kr.co.vividnext.sodalive.member.MemberRepository
|
||||
import org.springframework.data.domain.Pageable
|
||||
import org.springframework.stereotype.Service
|
||||
import java.time.ZoneId
|
||||
@@ -13,7 +14,8 @@ import java.time.format.DateTimeFormatter
|
||||
@Service
|
||||
class CanService(
|
||||
private val repository: CanRepository,
|
||||
private val countryContext: CountryContext
|
||||
private val countryContext: CountryContext,
|
||||
private val memberRepository: MemberRepository
|
||||
) {
|
||||
fun getCans(isNotSelectedCurrency: Boolean): List<CanResponse> {
|
||||
val currency = if (isNotSelectedCurrency) {
|
||||
@@ -40,7 +42,7 @@ class CanService(
|
||||
timezone: String,
|
||||
container: String
|
||||
): List<GetCanUseStatusResponseItem> {
|
||||
return repository.getCanUseStatus(member, pageable)
|
||||
val useCanList = repository.getCanUseStatus(member, pageable)
|
||||
.filter { (it.can + it.rewardCan) > 0 }
|
||||
.filter {
|
||||
when (container) {
|
||||
@@ -66,6 +68,21 @@ class CanService(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val channelDonationCreatorIds = useCanList
|
||||
.asSequence()
|
||||
.filter { it.canUsage == CanUsage.CHANNEL_DONATION }
|
||||
.mapNotNull { it.useCanCalculates.firstOrNull()?.recipientCreatorId }
|
||||
.distinct()
|
||||
.toList()
|
||||
|
||||
val channelDonationCreatorNicknameMap = if (channelDonationCreatorIds.isEmpty()) {
|
||||
emptyMap()
|
||||
} else {
|
||||
memberRepository.findAllById(channelDonationCreatorIds).associate { it.id!! to it.nickname }
|
||||
}
|
||||
|
||||
return useCanList
|
||||
.map {
|
||||
val title: String = when (it.canUsage) {
|
||||
CanUsage.HEART, CanUsage.DONATION, CanUsage.SPIN_ROULETTE -> {
|
||||
@@ -78,6 +95,17 @@ class CanService(
|
||||
}
|
||||
}
|
||||
|
||||
CanUsage.CHANNEL_DONATION -> {
|
||||
val creatorId = it.useCanCalculates.firstOrNull()?.recipientCreatorId
|
||||
val creatorNickname = creatorId?.let { id -> channelDonationCreatorNicknameMap[id] }
|
||||
|
||||
if (creatorNickname.isNullOrBlank()) {
|
||||
"[채널 후원]"
|
||||
} else {
|
||||
"[채널 후원] $creatorNickname"
|
||||
}
|
||||
}
|
||||
|
||||
CanUsage.LIVE -> {
|
||||
"[라이브] ${it.room!!.title}"
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ class CanPaymentService(
|
||||
characterId: Long? = null,
|
||||
isSecret: Boolean = false,
|
||||
liveRoom: LiveRoom? = null,
|
||||
creator: Member? = null,
|
||||
order: Order? = null,
|
||||
audioContent: AudioContent? = null,
|
||||
communityPost: CreatorCommunity? = null,
|
||||
@@ -93,6 +94,9 @@ class CanPaymentService(
|
||||
recipientId = liveRoom.member!!.id!!
|
||||
useCan.room = liveRoom
|
||||
useCan.member = member
|
||||
} else if (canUsage == CanUsage.CHANNEL_DONATION && creator != null) {
|
||||
recipientId = creator.id!!
|
||||
useCan.member = member
|
||||
} else if (canUsage == CanUsage.ORDER_CONTENT && order != null) {
|
||||
recipientId = order.creator!!.id!!
|
||||
useCan.order = order
|
||||
|
||||
@@ -4,6 +4,7 @@ enum class CanUsage {
|
||||
LIVE,
|
||||
HEART,
|
||||
DONATION,
|
||||
CHANNEL_DONATION, // 채널 후원
|
||||
CHANGE_NICKNAME,
|
||||
ORDER_CONTENT,
|
||||
SPIN_ROULETTE,
|
||||
|
||||
@@ -17,6 +17,7 @@ import kr.co.vividnext.sodalive.explorer.profile.CreatorCheersRepository
|
||||
import kr.co.vividnext.sodalive.explorer.profile.CreatorDonationRankingService
|
||||
import kr.co.vividnext.sodalive.explorer.profile.PostWriteCheersRequest
|
||||
import kr.co.vividnext.sodalive.explorer.profile.PutWriteCheersRequest
|
||||
import kr.co.vividnext.sodalive.explorer.profile.channelDonation.ChannelDonationService
|
||||
import kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.CreatorCommunityService
|
||||
import kr.co.vividnext.sodalive.fcm.FcmEvent
|
||||
import kr.co.vividnext.sodalive.fcm.FcmEventType
|
||||
@@ -51,6 +52,7 @@ class ExplorerService(
|
||||
private val queryRepository: ExplorerQueryRepository,
|
||||
private val cheersRepository: CreatorCheersRepository,
|
||||
private val noticeRepository: ChannelNoticeRepository,
|
||||
private val channelDonationService: ChannelDonationService,
|
||||
private val communityService: CreatorCommunityService,
|
||||
private val seriesService: ContentSeriesService,
|
||||
|
||||
@@ -394,6 +396,16 @@ class ExplorerService(
|
||||
limit = 4
|
||||
)
|
||||
|
||||
val channelDonationList = if (isCreator && !isBlock) {
|
||||
channelDonationService.getChannelDonationListForProfile(
|
||||
creatorId = creatorId,
|
||||
member = member,
|
||||
limit = 5
|
||||
)
|
||||
} else {
|
||||
listOf()
|
||||
}
|
||||
|
||||
// 차단한 크리에이터 인지 체크
|
||||
val activitySummary = if (isCreator) {
|
||||
// 활동요약 (라이브 횟수, 라이브 시간, 라이브 참여자, 콘텐츠 수)
|
||||
@@ -455,6 +467,7 @@ class ExplorerService(
|
||||
ownedContentCount = ownedContentCount,
|
||||
notice = notice,
|
||||
communityPostList = communityPostList,
|
||||
channelDonationList = channelDonationList,
|
||||
cheers = cheers,
|
||||
activitySummary = activitySummary,
|
||||
seriesList = seriesList,
|
||||
|
||||
@@ -2,6 +2,7 @@ package kr.co.vividnext.sodalive.explorer
|
||||
|
||||
import kr.co.vividnext.sodalive.content.GetAudioContentListItem
|
||||
import kr.co.vividnext.sodalive.content.series.GetSeriesListResponse
|
||||
import kr.co.vividnext.sodalive.explorer.profile.channelDonation.GetChannelDonationListItem
|
||||
import kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.GetCommunityPostListResponse
|
||||
|
||||
data class GetCreatorProfileResponse(
|
||||
@@ -15,6 +16,7 @@ data class GetCreatorProfileResponse(
|
||||
val ownedContentCount: Long,
|
||||
val notice: String,
|
||||
val communityPostList: List<GetCommunityPostListResponse>,
|
||||
val channelDonationList: List<GetChannelDonationListItem>,
|
||||
val cheers: GetCheersResponse,
|
||||
val activitySummary: GetCreatorActivitySummary,
|
||||
val seriesList: List<GetSeriesListResponse.SeriesListItem>,
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package kr.co.vividnext.sodalive.explorer.profile.channelDonation
|
||||
|
||||
import kr.co.vividnext.sodalive.common.ApiResponse
|
||||
import kr.co.vividnext.sodalive.common.SodaException
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import org.springframework.data.domain.Pageable
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.PostMapping
|
||||
import org.springframework.web.bind.annotation.RequestBody
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RequestParam
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/explorer/profile/channel-donation")
|
||||
class ChannelDonationController(
|
||||
private val channelDonationService: ChannelDonationService
|
||||
) {
|
||||
@PostMapping
|
||||
fun donate(
|
||||
@RequestBody request: PostChannelDonationRequest,
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
||||
) = run {
|
||||
if (member == null) throw SodaException(messageKey = "common.error.bad_credentials")
|
||||
ApiResponse.ok(channelDonationService.donate(request, member))
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
fun getChannelDonationList(
|
||||
@RequestParam creatorId: Long,
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?,
|
||||
pageable: Pageable
|
||||
) = run {
|
||||
if (member == null) throw SodaException(messageKey = "common.error.bad_credentials")
|
||||
ApiResponse.ok(
|
||||
channelDonationService.getChannelDonationList(
|
||||
creatorId = creatorId,
|
||||
member = member,
|
||||
offset = pageable.offset,
|
||||
limit = pageable.pageSize.toLong()
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package kr.co.vividnext.sodalive.explorer.profile.channelDonation
|
||||
|
||||
import kr.co.vividnext.sodalive.common.BaseEntity
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import javax.persistence.Column
|
||||
import javax.persistence.Entity
|
||||
import javax.persistence.FetchType
|
||||
import javax.persistence.JoinColumn
|
||||
import javax.persistence.ManyToOne
|
||||
|
||||
@Entity
|
||||
class ChannelDonationMessage(
|
||||
val can: Int,
|
||||
val isSecret: Boolean = false,
|
||||
@Column(columnDefinition = "TEXT")
|
||||
var additionalMessage: String? = null
|
||||
) : BaseEntity() {
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "member_id", nullable = false)
|
||||
var member: Member? = null
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "creator_id", nullable = false)
|
||||
var creator: Member? = null
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package kr.co.vividnext.sodalive.explorer.profile.channelDonation
|
||||
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory
|
||||
import kr.co.vividnext.sodalive.explorer.profile.channelDonation.QChannelDonationMessage.channelDonationMessage
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.stereotype.Repository
|
||||
import java.time.LocalDateTime
|
||||
|
||||
@Repository
|
||||
interface ChannelDonationMessageRepository :
|
||||
JpaRepository<ChannelDonationMessage, Long>, ChannelDonationMessageQueryRepository
|
||||
|
||||
interface ChannelDonationMessageQueryRepository {
|
||||
fun getChannelDonationMessageList(
|
||||
creatorId: Long,
|
||||
memberId: Long,
|
||||
isCreator: Boolean,
|
||||
offset: Long,
|
||||
limit: Long,
|
||||
startDateTime: LocalDateTime
|
||||
): List<ChannelDonationMessage>
|
||||
|
||||
fun getChannelDonationMessageTotalCount(
|
||||
creatorId: Long,
|
||||
memberId: Long,
|
||||
isCreator: Boolean,
|
||||
startDateTime: LocalDateTime
|
||||
): Int
|
||||
}
|
||||
|
||||
class ChannelDonationMessageQueryRepositoryImpl(
|
||||
private val queryFactory: JPAQueryFactory
|
||||
) : ChannelDonationMessageQueryRepository {
|
||||
override fun getChannelDonationMessageList(
|
||||
creatorId: Long,
|
||||
memberId: Long,
|
||||
isCreator: Boolean,
|
||||
offset: Long,
|
||||
limit: Long,
|
||||
startDateTime: LocalDateTime
|
||||
): List<ChannelDonationMessage> {
|
||||
val where = whereCondition(
|
||||
creatorId = creatorId,
|
||||
memberId = memberId,
|
||||
isCreator = isCreator,
|
||||
startDateTime = startDateTime
|
||||
)
|
||||
|
||||
return queryFactory
|
||||
.selectFrom(channelDonationMessage)
|
||||
.where(where)
|
||||
.offset(offset)
|
||||
.limit(limit)
|
||||
.orderBy(
|
||||
channelDonationMessage.createdAt.desc(),
|
||||
channelDonationMessage.id.desc()
|
||||
)
|
||||
.fetch()
|
||||
}
|
||||
|
||||
override fun getChannelDonationMessageTotalCount(
|
||||
creatorId: Long,
|
||||
memberId: Long,
|
||||
isCreator: Boolean,
|
||||
startDateTime: LocalDateTime
|
||||
): Int {
|
||||
val where = whereCondition(
|
||||
creatorId = creatorId,
|
||||
memberId = memberId,
|
||||
isCreator = isCreator,
|
||||
startDateTime = startDateTime
|
||||
)
|
||||
|
||||
return queryFactory
|
||||
.select(channelDonationMessage.id)
|
||||
.from(channelDonationMessage)
|
||||
.where(where)
|
||||
.fetch()
|
||||
.size
|
||||
}
|
||||
|
||||
private fun whereCondition(
|
||||
creatorId: Long,
|
||||
memberId: Long,
|
||||
isCreator: Boolean,
|
||||
startDateTime: LocalDateTime
|
||||
) = channelDonationMessage.creator.id.eq(creatorId)
|
||||
.and(channelDonationMessage.createdAt.goe(startDateTime))
|
||||
.let {
|
||||
if (isCreator) {
|
||||
it
|
||||
} else {
|
||||
it.and(
|
||||
channelDonationMessage.isSecret.isFalse
|
||||
.or(channelDonationMessage.member.id.eq(memberId))
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package kr.co.vividnext.sodalive.explorer.profile.channelDonation
|
||||
|
||||
import kr.co.vividnext.sodalive.can.payment.CanPaymentService
|
||||
import kr.co.vividnext.sodalive.can.use.CanUsage
|
||||
import kr.co.vividnext.sodalive.common.SodaException
|
||||
import kr.co.vividnext.sodalive.i18n.LangContext
|
||||
import kr.co.vividnext.sodalive.i18n.SodaMessageSource
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import kr.co.vividnext.sodalive.member.MemberRepository
|
||||
import kr.co.vividnext.sodalive.member.MemberRole
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.stereotype.Service
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
@Service
|
||||
class ChannelDonationService(
|
||||
private val canPaymentService: CanPaymentService,
|
||||
private val memberRepository: MemberRepository,
|
||||
private val channelDonationMessageRepository: ChannelDonationMessageRepository,
|
||||
private val messageSource: SodaMessageSource,
|
||||
private val langContext: LangContext,
|
||||
@Value("\${cloud.aws.cloud-front.host}")
|
||||
private val cloudFrontHost: String
|
||||
) {
|
||||
@Transactional
|
||||
fun donate(request: PostChannelDonationRequest, member: Member) {
|
||||
if (request.can < 1) {
|
||||
throw SodaException(messageKey = "content.donation.error.minimum_can")
|
||||
}
|
||||
|
||||
val creator = memberRepository.findCreatorByIdOrNull(request.creatorId)
|
||||
?: throw SodaException(messageKey = "member.validation.creator_not_found")
|
||||
|
||||
canPaymentService.spendCan(
|
||||
memberId = member.id!!,
|
||||
needCan = request.can,
|
||||
canUsage = CanUsage.CHANNEL_DONATION,
|
||||
creator = creator,
|
||||
isSecret = request.isSecret,
|
||||
container = request.container
|
||||
)
|
||||
|
||||
val channelDonationMessage = ChannelDonationMessage(
|
||||
can = request.can,
|
||||
isSecret = request.isSecret,
|
||||
additionalMessage = request.message.takeIf { it.isNotBlank() }
|
||||
)
|
||||
channelDonationMessage.member = member
|
||||
channelDonationMessage.creator = creator
|
||||
channelDonationMessageRepository.save(channelDonationMessage)
|
||||
}
|
||||
|
||||
fun getChannelDonationList(
|
||||
creatorId: Long,
|
||||
member: Member,
|
||||
offset: Long,
|
||||
limit: Long
|
||||
): GetChannelDonationListResponse {
|
||||
memberRepository.findCreatorByIdOrNull(creatorId)
|
||||
?: throw SodaException(messageKey = "member.validation.creator_not_found")
|
||||
|
||||
val startDateTime = LocalDateTime.now().minusMonths(1)
|
||||
val isCreator = member.role == MemberRole.CREATOR && creatorId == member.id
|
||||
|
||||
val totalCount = channelDonationMessageRepository.getChannelDonationMessageTotalCount(
|
||||
creatorId = creatorId,
|
||||
memberId = member.id!!,
|
||||
isCreator = isCreator,
|
||||
startDateTime = startDateTime
|
||||
)
|
||||
|
||||
val items = channelDonationMessageRepository.getChannelDonationMessageList(
|
||||
creatorId = creatorId,
|
||||
memberId = member.id!!,
|
||||
isCreator = isCreator,
|
||||
offset = offset,
|
||||
limit = limit,
|
||||
startDateTime = startDateTime
|
||||
).map {
|
||||
GetChannelDonationListItem(
|
||||
id = it.id!!,
|
||||
memberId = it.member!!.id!!,
|
||||
nickname = it.member!!.nickname,
|
||||
profileUrl = if (it.member!!.profileImage != null) {
|
||||
"$cloudFrontHost/${it.member!!.profileImage}"
|
||||
} else {
|
||||
"$cloudFrontHost/profile/default-profile.png"
|
||||
},
|
||||
can = it.can,
|
||||
isSecret = it.isSecret,
|
||||
message = buildMessage(it.can, it.isSecret, it.additionalMessage),
|
||||
createdAt = it.createdAt!!.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
|
||||
)
|
||||
}
|
||||
|
||||
return GetChannelDonationListResponse(totalCount = totalCount, items = items)
|
||||
}
|
||||
|
||||
fun getChannelDonationListForProfile(
|
||||
creatorId: Long,
|
||||
member: Member,
|
||||
limit: Long = 5
|
||||
): List<GetChannelDonationListItem> {
|
||||
return getChannelDonationList(
|
||||
creatorId = creatorId,
|
||||
member = member,
|
||||
offset = 0,
|
||||
limit = limit
|
||||
).items
|
||||
}
|
||||
|
||||
private fun buildMessage(can: Int, isSecret: Boolean, additionalMessage: String?): String {
|
||||
val key = if (isSecret) {
|
||||
"explorer.channel_donation.message.default.secret"
|
||||
} else {
|
||||
"explorer.channel_donation.message.default.public"
|
||||
}
|
||||
val defaultMessage = getMessage(key, can)
|
||||
|
||||
return if (additionalMessage.isNullOrBlank()) {
|
||||
defaultMessage
|
||||
} else {
|
||||
"$defaultMessage\n\"$additionalMessage\""
|
||||
}
|
||||
}
|
||||
|
||||
private fun getMessage(key: String, vararg args: Any): String {
|
||||
val template = messageSource.getMessage(key, langContext.lang).orEmpty()
|
||||
return if (args.isEmpty()) template else String.format(template, *args)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package kr.co.vividnext.sodalive.explorer.profile.channelDonation
|
||||
|
||||
data class GetChannelDonationListResponse(
|
||||
val totalCount: Int,
|
||||
val items: List<GetChannelDonationListItem>
|
||||
)
|
||||
|
||||
data class GetChannelDonationListItem(
|
||||
val id: Long,
|
||||
val memberId: Long,
|
||||
val nickname: String,
|
||||
val profileUrl: String,
|
||||
val can: Int,
|
||||
val isSecret: Boolean,
|
||||
val message: String,
|
||||
val createdAt: String
|
||||
)
|
||||
@@ -0,0 +1,9 @@
|
||||
package kr.co.vividnext.sodalive.explorer.profile.channelDonation
|
||||
|
||||
data class PostChannelDonationRequest(
|
||||
val creatorId: Long,
|
||||
val can: Int,
|
||||
val isSecret: Boolean = false,
|
||||
val message: String = "",
|
||||
val container: String
|
||||
)
|
||||
@@ -1770,6 +1770,16 @@ class SodaMessageSource {
|
||||
Lang.KO to "새 글이 등록되었습니다.",
|
||||
Lang.EN to "A new post has been added.",
|
||||
Lang.JA to "新しい投稿が登録されました。"
|
||||
),
|
||||
"explorer.channel_donation.message.default.public" to mapOf(
|
||||
Lang.KO to "%s캔을 후원하셨습니다.",
|
||||
Lang.EN to "You sponsored %s cans.",
|
||||
Lang.JA to "%sCANを支援しました。"
|
||||
),
|
||||
"explorer.channel_donation.message.default.secret" to mapOf(
|
||||
Lang.KO to "%s캔을 비밀후원하셨습니다.",
|
||||
Lang.EN to "You secretly sponsored %s cans.",
|
||||
Lang.JA to "%sCANをシークレット支援しました。"
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user