콘텐츠 메인
- 홈 탭 API
This commit is contained in:
@@ -0,0 +1,318 @@
|
||||
package kr.co.vividnext.sodalive.rank
|
||||
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory
|
||||
import kr.co.vividnext.sodalive.content.QAudioContent.audioContent
|
||||
import kr.co.vividnext.sodalive.content.comment.QAudioContentComment.audioContentComment
|
||||
import kr.co.vividnext.sodalive.content.like.QAudioContentLike.audioContentLike
|
||||
import kr.co.vividnext.sodalive.content.main.ContentCreatorResponse
|
||||
import kr.co.vividnext.sodalive.content.main.GetAudioContentRankingItem
|
||||
import kr.co.vividnext.sodalive.content.main.QContentCreatorResponse
|
||||
import kr.co.vividnext.sodalive.content.main.QGetAudioContentRankingItem
|
||||
import kr.co.vividnext.sodalive.content.order.QOrder.order
|
||||
import kr.co.vividnext.sodalive.content.theme.QAudioContentTheme.audioContentTheme
|
||||
import kr.co.vividnext.sodalive.creator.admin.content.series.QSeries.series
|
||||
import kr.co.vividnext.sodalive.creator.admin.content.series.QSeriesContent.seriesContent
|
||||
import kr.co.vividnext.sodalive.creator.admin.content.series.Series
|
||||
import kr.co.vividnext.sodalive.explorer.QCreatorRanking.creatorRanking
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import kr.co.vividnext.sodalive.member.MemberRole
|
||||
import kr.co.vividnext.sodalive.member.QMember.member
|
||||
import kr.co.vividnext.sodalive.member.block.QBlockMember.blockMember
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.stereotype.Repository
|
||||
import java.time.LocalDateTime
|
||||
|
||||
@Repository
|
||||
class RankingRepository(
|
||||
private val queryFactory: JPAQueryFactory,
|
||||
|
||||
@Value("\${cloud.aws.cloud-front.host}")
|
||||
private val imageHost: String
|
||||
) {
|
||||
fun getCreatorRankings(): List<Member> {
|
||||
return queryFactory
|
||||
.select(member)
|
||||
.from(creatorRanking)
|
||||
.innerJoin(creatorRanking.member, member)
|
||||
.orderBy(creatorRanking.ranking.asc())
|
||||
.fetch()
|
||||
}
|
||||
|
||||
fun getAudioContentRanking(
|
||||
memberId: Long,
|
||||
isAdult: Boolean,
|
||||
startDate: LocalDateTime,
|
||||
endDate: LocalDateTime,
|
||||
offset: Long,
|
||||
limit: Long,
|
||||
sortType: String
|
||||
): List<GetAudioContentRankingItem> {
|
||||
val blockMemberCondition = blockMember.member.id.eq(member.id)
|
||||
.and(blockMember.isActive.isTrue)
|
||||
.and(blockMember.blockedMember.id.eq(memberId))
|
||||
|
||||
var where = audioContent.isActive.isTrue
|
||||
.and(audioContent.member.isActive.isTrue)
|
||||
.and(audioContent.member.isNotNull)
|
||||
.and(audioContent.member.role.eq(MemberRole.CREATOR))
|
||||
.and(audioContent.duration.isNotNull)
|
||||
.and(audioContentTheme.isActive.isTrue)
|
||||
.and(audioContent.limited.isNull)
|
||||
.and(blockMember.id.isNull)
|
||||
|
||||
if (!isAdult) {
|
||||
where = where.and(audioContent.isAdult.isFalse)
|
||||
}
|
||||
|
||||
var select = queryFactory
|
||||
.select(
|
||||
QGetAudioContentRankingItem(
|
||||
audioContent.id,
|
||||
audioContent.title,
|
||||
audioContent.coverImage.prepend("/").prepend(imageHost),
|
||||
audioContentTheme.theme,
|
||||
audioContent.price,
|
||||
audioContent.duration,
|
||||
member.id,
|
||||
member.nickname
|
||||
)
|
||||
)
|
||||
|
||||
select = when (sortType) {
|
||||
"후원" -> {
|
||||
select
|
||||
.from(audioContentComment)
|
||||
.innerJoin(audioContentComment.audioContent, audioContent)
|
||||
.innerJoin(audioContent.member, member)
|
||||
.innerJoin(audioContent.theme, audioContentTheme)
|
||||
.leftJoin(blockMember).on(blockMemberCondition)
|
||||
.where(
|
||||
where
|
||||
.and(audioContentComment.isActive.isTrue)
|
||||
.and(audioContentComment.donationCan.gt(0))
|
||||
.and(audioContentComment.createdAt.goe(startDate))
|
||||
.and(audioContentComment.createdAt.lt(endDate))
|
||||
)
|
||||
.groupBy(audioContent.id)
|
||||
.orderBy(audioContentComment.donationCan.sum().desc(), audioContent.createdAt.asc())
|
||||
}
|
||||
|
||||
"댓글" -> {
|
||||
select
|
||||
.from(audioContentComment)
|
||||
.innerJoin(audioContentComment.audioContent, audioContent)
|
||||
.innerJoin(audioContent.member, member)
|
||||
.innerJoin(audioContent.theme, audioContentTheme)
|
||||
.leftJoin(blockMember).on(blockMemberCondition)
|
||||
.where(
|
||||
where
|
||||
.and(audioContentComment.isActive.isTrue)
|
||||
.and(audioContentComment.createdAt.goe(startDate))
|
||||
.and(audioContentComment.createdAt.lt(endDate))
|
||||
)
|
||||
.groupBy(audioContentComment.audioContent.id)
|
||||
.orderBy(audioContentComment.id.count().desc(), audioContent.createdAt.asc())
|
||||
}
|
||||
|
||||
"좋아요" -> {
|
||||
select
|
||||
.from(audioContentLike)
|
||||
.innerJoin(audioContentLike.audioContent, audioContent)
|
||||
.innerJoin(audioContent.member, member)
|
||||
.innerJoin(audioContent.theme, audioContentTheme)
|
||||
.leftJoin(blockMember).on(blockMemberCondition)
|
||||
.where(
|
||||
where
|
||||
.and(audioContentLike.isActive.isTrue)
|
||||
.and(audioContentLike.createdAt.goe(startDate))
|
||||
.and(audioContentLike.createdAt.lt(endDate))
|
||||
)
|
||||
.groupBy(audioContentLike.audioContent.id)
|
||||
.orderBy(audioContentLike.id.count().desc(), audioContent.createdAt.asc())
|
||||
}
|
||||
|
||||
else -> {
|
||||
select
|
||||
.from(order)
|
||||
.innerJoin(order.audioContent, audioContent)
|
||||
.innerJoin(audioContent.member, member)
|
||||
.innerJoin(audioContent.theme, audioContentTheme)
|
||||
.leftJoin(blockMember).on(blockMemberCondition)
|
||||
.where(
|
||||
where
|
||||
.and(order.isActive.isTrue)
|
||||
.and(order.createdAt.goe(startDate))
|
||||
.and(order.createdAt.lt(endDate))
|
||||
)
|
||||
.groupBy(audioContent.id)
|
||||
.orderBy(order.can.sum().desc(), audioContent.createdAt.asc())
|
||||
}
|
||||
}
|
||||
|
||||
return select
|
||||
.offset(offset)
|
||||
.limit(limit)
|
||||
.fetch()
|
||||
}
|
||||
|
||||
fun getSeriesRanking(
|
||||
memberId: Long,
|
||||
isAdult: Boolean,
|
||||
startDate: LocalDateTime,
|
||||
endDate: LocalDateTime
|
||||
): List<Series> {
|
||||
val blockMemberCondition = blockMember.member.id.eq(member.id)
|
||||
.and(blockMember.isActive.isTrue)
|
||||
.and(blockMember.blockedMember.id.eq(memberId))
|
||||
|
||||
var where = series.isActive.isTrue
|
||||
.and(audioContent.isActive.isTrue)
|
||||
.and(member.isActive.isTrue)
|
||||
.and(member.isNotNull)
|
||||
.and(member.role.eq(MemberRole.CREATOR))
|
||||
.and(audioContent.duration.isNotNull)
|
||||
.and(audioContent.limited.isNull)
|
||||
.and(blockMember.id.isNull)
|
||||
.and(order.isActive.isTrue)
|
||||
.and(order.createdAt.goe(startDate))
|
||||
.and(order.createdAt.lt(endDate))
|
||||
|
||||
if (!isAdult) {
|
||||
where = where.and(series.isAdult.isFalse)
|
||||
}
|
||||
|
||||
return queryFactory
|
||||
.select(series)
|
||||
.from(seriesContent)
|
||||
.innerJoin(seriesContent.series, series)
|
||||
.innerJoin(seriesContent.content, audioContent)
|
||||
.innerJoin(series.member, member)
|
||||
.innerJoin(order).on(audioContent.id.eq(order.audioContent.id))
|
||||
.leftJoin(blockMember).on(blockMemberCondition)
|
||||
.where(where)
|
||||
.groupBy(series.id)
|
||||
.orderBy(order.can.sum().desc(), series.createdAt.asc())
|
||||
.offset(0)
|
||||
.limit(10)
|
||||
.fetch()
|
||||
}
|
||||
|
||||
fun fetchCreatorByContentRevenueRankTop20(
|
||||
memberId: Long,
|
||||
startDate: LocalDateTime,
|
||||
endDate: LocalDateTime
|
||||
): List<ContentCreatorResponse> {
|
||||
val blockMemberCondition = blockMember.member.id.eq(member.id)
|
||||
.and(blockMember.isActive.isTrue)
|
||||
.and(blockMember.blockedMember.id.eq(memberId))
|
||||
|
||||
val ordersCondition = order.audioContent.id.eq(audioContent.id)
|
||||
.and(order.isActive.isTrue)
|
||||
.and(order.createdAt.goe(startDate))
|
||||
.and(order.createdAt.lt(startDate))
|
||||
|
||||
val where = member.isActive.isTrue
|
||||
.and(member.role.eq(MemberRole.CREATOR))
|
||||
.and(audioContent.isActive.isTrue)
|
||||
.and(audioContent.duration.isNotNull)
|
||||
.and(audioContent.limited.isNull)
|
||||
.and(blockMember.id.isNull)
|
||||
|
||||
return queryFactory
|
||||
.select(
|
||||
QContentCreatorResponse(
|
||||
member.id,
|
||||
member.nickname,
|
||||
member.profileImage.prepend("/").prepend(imageHost)
|
||||
)
|
||||
)
|
||||
.from(member)
|
||||
.innerJoin(audioContent).on(member.id.eq(audioContent.member.id))
|
||||
.leftJoin(order).on(ordersCondition)
|
||||
.leftJoin(blockMember).on(blockMemberCondition)
|
||||
.where(where)
|
||||
.groupBy(member.id)
|
||||
.having(
|
||||
audioContent.id.count().goe(4)
|
||||
.and(order.can.sum().gt(0))
|
||||
)
|
||||
.orderBy(order.can.sum().desc())
|
||||
.offset(0)
|
||||
.limit(20)
|
||||
.fetch()
|
||||
}
|
||||
|
||||
fun fetchCreatorContentBySalesTop2(creatorId: Long, isAdult: Boolean): List<GetAudioContentRankingItem> {
|
||||
var where = member.isActive.isTrue
|
||||
.and(member.role.eq(MemberRole.CREATOR))
|
||||
.and(audioContent.isActive.isTrue)
|
||||
.and(audioContent.duration.isNotNull)
|
||||
.and(audioContent.limited.isNull)
|
||||
.and(order.isActive.isTrue)
|
||||
.and(member.id.eq(creatorId))
|
||||
|
||||
if (!isAdult) {
|
||||
where = where.and(series.isAdult.isFalse)
|
||||
}
|
||||
|
||||
return queryFactory
|
||||
.select(
|
||||
QGetAudioContentRankingItem(
|
||||
audioContent.id,
|
||||
audioContent.title,
|
||||
audioContent.coverImage.prepend("/").prepend(imageHost),
|
||||
audioContentTheme.theme,
|
||||
audioContent.price,
|
||||
audioContent.duration,
|
||||
member.id,
|
||||
member.nickname
|
||||
)
|
||||
)
|
||||
.from(order)
|
||||
.innerJoin(order.audioContent, audioContent)
|
||||
.innerJoin(audioContent.member, member)
|
||||
.where(where)
|
||||
.groupBy(audioContent.id)
|
||||
.orderBy(order.can.sum().desc())
|
||||
.offset(0)
|
||||
.limit(2)
|
||||
.fetch()
|
||||
}
|
||||
|
||||
fun fetchCreatorContentBySalesCountTop2(creatorId: Long, isAdult: Boolean): List<GetAudioContentRankingItem> {
|
||||
var where = member.isActive.isTrue
|
||||
.and(member.role.eq(MemberRole.CREATOR))
|
||||
.and(audioContent.isActive.isTrue)
|
||||
.and(audioContent.duration.isNotNull)
|
||||
.and(audioContent.limited.isNull)
|
||||
.and(order.isActive.isTrue)
|
||||
.and(member.id.eq(creatorId))
|
||||
|
||||
if (!isAdult) {
|
||||
where = where.and(series.isAdult.isFalse)
|
||||
}
|
||||
|
||||
return queryFactory
|
||||
.select(
|
||||
QGetAudioContentRankingItem(
|
||||
audioContent.id,
|
||||
audioContent.title,
|
||||
audioContent.coverImage.prepend("/").prepend(imageHost),
|
||||
audioContentTheme.theme,
|
||||
audioContent.price,
|
||||
audioContent.duration,
|
||||
member.id,
|
||||
member.nickname
|
||||
)
|
||||
)
|
||||
.from(order)
|
||||
.innerJoin(order.audioContent, audioContent)
|
||||
.innerJoin(audioContent.member, member)
|
||||
.where(where)
|
||||
.groupBy(audioContent.id)
|
||||
.orderBy(order.id.count().desc())
|
||||
.offset(0)
|
||||
.limit(2)
|
||||
.fetch()
|
||||
}
|
||||
}
|
151
src/main/kotlin/kr/co/vividnext/sodalive/rank/RankingService.kt
Normal file
151
src/main/kotlin/kr/co/vividnext/sodalive/rank/RankingService.kt
Normal file
@@ -0,0 +1,151 @@
|
||||
package kr.co.vividnext.sodalive.rank
|
||||
|
||||
import kr.co.vividnext.sodalive.content.main.ContentCreatorResponse
|
||||
import kr.co.vividnext.sodalive.content.main.GetAudioContentRankingItem
|
||||
import kr.co.vividnext.sodalive.content.series.GetSeriesListResponse
|
||||
import kr.co.vividnext.sodalive.content.series.content.ContentSeriesContentRepository
|
||||
import kr.co.vividnext.sodalive.creator.admin.content.series.Series
|
||||
import kr.co.vividnext.sodalive.creator.admin.content.series.SeriesPublishedDaysOfWeek
|
||||
import kr.co.vividnext.sodalive.creator.admin.content.series.SeriesState
|
||||
import kr.co.vividnext.sodalive.explorer.GetExplorerSectionResponse
|
||||
import kr.co.vividnext.sodalive.member.MemberService
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.stereotype.Service
|
||||
import java.time.LocalDateTime
|
||||
|
||||
@Service
|
||||
class RankingService(
|
||||
private val repository: RankingRepository,
|
||||
private val memberService: MemberService,
|
||||
private val seriesContentRepository: ContentSeriesContentRepository,
|
||||
|
||||
@Value("\${cloud.aws.cloud-front.host}")
|
||||
private val imageHost: String
|
||||
) {
|
||||
fun getCreatorRanking(memberId: Long, rankingDate: String): GetExplorerSectionResponse {
|
||||
val creatorRankings = repository
|
||||
.getCreatorRankings()
|
||||
.filter { !memberService.isBlocked(blockedMemberId = memberId, memberId = it.id!!) }
|
||||
.map { it.toExplorerSectionCreator(imageHost) }
|
||||
|
||||
return GetExplorerSectionResponse(
|
||||
title = "인기 크리에이터",
|
||||
coloredTitle = "인기",
|
||||
color = "FF5C49",
|
||||
desc = rankingDate,
|
||||
creators = creatorRankings
|
||||
)
|
||||
}
|
||||
|
||||
fun getContentRanking(
|
||||
memberId: Long,
|
||||
isAdult: Boolean,
|
||||
startDate: LocalDateTime,
|
||||
endDate: LocalDateTime,
|
||||
offset: Long = 0,
|
||||
limit: Long = 12,
|
||||
sortType: String = "매출"
|
||||
): List<GetAudioContentRankingItem> {
|
||||
return repository.getAudioContentRanking(
|
||||
memberId = memberId,
|
||||
isAdult = isAdult,
|
||||
startDate = startDate,
|
||||
endDate = endDate,
|
||||
offset = offset,
|
||||
limit = limit,
|
||||
sortType = sortType
|
||||
)
|
||||
}
|
||||
|
||||
fun getSeriesRanking(
|
||||
memberId: Long,
|
||||
isAdult: Boolean,
|
||||
startDate: LocalDateTime,
|
||||
endDate: LocalDateTime
|
||||
): List<GetSeriesListResponse.SeriesListItem> {
|
||||
val seriesList = repository.getSeriesRanking(memberId, isAdult, startDate, endDate)
|
||||
return seriesToSeriesListItem(seriesList = seriesList, isAdult = isAdult)
|
||||
}
|
||||
|
||||
private fun seriesToSeriesListItem(
|
||||
seriesList: List<Series>,
|
||||
isAdult: Boolean
|
||||
): List<GetSeriesListResponse.SeriesListItem> {
|
||||
return seriesList
|
||||
.map {
|
||||
GetSeriesListResponse.SeriesListItem(
|
||||
seriesId = it.id!!,
|
||||
title = it.title,
|
||||
coverImage = "$imageHost/${it.coverImage!!}",
|
||||
publishedDaysOfWeek = publishedDaysOfWeekText(it.publishedDaysOfWeek),
|
||||
isComplete = it.state == SeriesState.COMPLETE,
|
||||
creator = GetSeriesListResponse.SeriesListItemCreator(
|
||||
creatorId = it.member!!.id!!,
|
||||
nickname = it.member!!.nickname,
|
||||
profileImage = "$imageHost/${it.member!!.profileImage!!}"
|
||||
)
|
||||
)
|
||||
}
|
||||
.map {
|
||||
it.numberOfContent = seriesContentRepository.getContentCount(
|
||||
seriesId = it.seriesId,
|
||||
isAdult = isAdult
|
||||
)
|
||||
|
||||
it
|
||||
}
|
||||
.map {
|
||||
val nowDateTime = LocalDateTime.now()
|
||||
|
||||
it.isNew = seriesContentRepository.isNewContent(
|
||||
seriesId = it.seriesId,
|
||||
isAdult = isAdult,
|
||||
fromDate = nowDateTime.minusDays(7),
|
||||
nowDate = nowDateTime
|
||||
)
|
||||
|
||||
it
|
||||
}
|
||||
}
|
||||
|
||||
private fun publishedDaysOfWeekText(publishedDaysOfWeek: Set<SeriesPublishedDaysOfWeek>): String {
|
||||
val dayOfWeekText = publishedDaysOfWeek.toList().sortedBy { it.ordinal }
|
||||
.map {
|
||||
when (it) {
|
||||
SeriesPublishedDaysOfWeek.SUN -> "일"
|
||||
SeriesPublishedDaysOfWeek.MON -> "월"
|
||||
SeriesPublishedDaysOfWeek.TUE -> "화"
|
||||
SeriesPublishedDaysOfWeek.WED -> "수"
|
||||
SeriesPublishedDaysOfWeek.THU -> "목"
|
||||
SeriesPublishedDaysOfWeek.FRI -> "금"
|
||||
SeriesPublishedDaysOfWeek.SAT -> "토"
|
||||
SeriesPublishedDaysOfWeek.RANDOM -> "랜덤"
|
||||
}
|
||||
}
|
||||
.joinToString(", ") { it }
|
||||
|
||||
return if (publishedDaysOfWeek.contains(SeriesPublishedDaysOfWeek.RANDOM)) {
|
||||
dayOfWeekText
|
||||
} else if (publishedDaysOfWeek.size < 7) {
|
||||
"매주 $dayOfWeekText"
|
||||
} else {
|
||||
"매일"
|
||||
}
|
||||
}
|
||||
|
||||
fun fetchCreatorByContentRevenueRankTop20(
|
||||
memberId: Long,
|
||||
startDate: LocalDateTime,
|
||||
endDate: LocalDateTime
|
||||
): List<ContentCreatorResponse> {
|
||||
return repository.fetchCreatorByContentRevenueRankTop20(memberId, startDate, endDate)
|
||||
}
|
||||
|
||||
fun fetchCreatorContentBySalesTop2(creatorId: Long, isAdult: Boolean): List<GetAudioContentRankingItem> {
|
||||
return repository.fetchCreatorContentBySalesTop2(creatorId, isAdult)
|
||||
}
|
||||
|
||||
fun fetchCreatorContentBySalesCountTop2(creatorId: Long, isAdult: Boolean): List<GetAudioContentRankingItem> {
|
||||
return repository.fetchCreatorContentBySalesCountTop2(creatorId, isAdult)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user