diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/CreatorRanking.kt b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/CreatorRanking.kt new file mode 100644 index 0000000..6104d6f --- /dev/null +++ b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/CreatorRanking.kt @@ -0,0 +1,22 @@ +package kr.co.vividnext.sodalive.explorer + +import kr.co.vividnext.sodalive.member.Member +import javax.persistence.Entity +import javax.persistence.FetchType +import javax.persistence.GeneratedValue +import javax.persistence.GenerationType +import javax.persistence.Id +import javax.persistence.JoinColumn +import javax.persistence.OneToOne + +@Entity +data class CreatorRanking( + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + var id: Long? = null, + val ranking: Int +) { + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "creator_id", nullable = false) + var member: Member? = null +} diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/ExplorerQueryRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/ExplorerQueryRepository.kt index eaad92d..7c1abf6 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/ExplorerQueryRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/ExplorerQueryRepository.kt @@ -10,6 +10,7 @@ import kr.co.vividnext.sodalive.can.use.QUseCanCalculate.useCanCalculate import kr.co.vividnext.sodalive.can.use.UseCanCalculateStatus import kr.co.vividnext.sodalive.common.SodaException import kr.co.vividnext.sodalive.content.QAudioContent.audioContent +import kr.co.vividnext.sodalive.explorer.QCreatorRanking.creatorRanking import kr.co.vividnext.sodalive.explorer.follower.GetFollowerListDto import kr.co.vividnext.sodalive.explorer.follower.QGetFollowerListDto import kr.co.vividnext.sodalive.explorer.profile.ChannelNotice @@ -158,21 +159,6 @@ class ExplorerQueryRepository( } } - fun getSubscriberGrowthRankingCreators(limit: Long): List { - return queryFactory - .selectFrom(member) - .join(member.follower, creatorFollowing) - .where( - member.role.eq(MemberRole.CREATOR) - .and(creatorFollowing.createdAt.goe(LocalDateTime.now().minusMonths(1))) - .and(creatorFollowing.isActive.isTrue) - ) - .groupBy(member.id) - .orderBy(member.follower.size().desc()) - .limit(limit) - .fetch() - } - fun getNewCreators(): List { return queryFactory .selectFrom(member) @@ -636,4 +622,13 @@ class ExplorerQueryRepository( .where(member.id.eq(creatorId)) .fetchFirst() } + + fun getCreatorRankings(): List { + return queryFactory + .select(member) + .from(creatorRanking) + .innerJoin(creatorRanking.member, member) + .orderBy(creatorRanking.ranking.asc()) + .fetch() + } } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/ExplorerService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/ExplorerService.kt index 3cd6682..0a752d3 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/ExplorerService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/ExplorerService.kt @@ -24,6 +24,8 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import java.time.DayOfWeek import java.time.LocalDate +import java.time.LocalDateTime +import java.time.format.DateTimeFormatter import java.time.temporal.TemporalAdjusters @Service @@ -42,9 +44,9 @@ class ExplorerService( fun getExplorer(member: Member, growthRankingCreatorsLimit: Long = 20): GetExplorerResponse { val sections = mutableListOf() - // 인기 급상승중 (subscriberGrowthRankingCreators) - val growthRankingCreators = queryRepository - .getSubscriberGrowthRankingCreators(limit = growthRankingCreatorsLimit) + // 인기 크리에이터 + val creatorRankings = queryRepository + .getCreatorRankings() .asSequence() .filter { !memberService.isBlocked(blockedMemberId = member.id!!, memberId = it.id!!) } .map { @@ -65,13 +67,25 @@ class ExplorerService( } .toList() - val growthRankingSection = GetExplorerSectionResponse( - title = "인기 급상승중", + val currentDateTime = LocalDateTime.now() + val lastMonday = currentDateTime + .minusWeeks(1) + .with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)) + val lastSunday = lastMonday + .plusDays(6) + + val formatter = DateTimeFormatter.ofPattern("MM월 dd일") + val formattedLastMonday = lastMonday.format(formatter) + val formattedLastSunday = lastSunday.format(formatter) + + val creatorRankingSection = GetExplorerSectionResponse( + title = "인기 크리에이터", coloredTitle = "인기", color = "FF5C49", - creators = growthRankingCreators + desc = "$formattedLastMonday~$formattedLastSunday\n※ 인기 크리에이터의 순위는 매주 업데이트 됩니다.", + creators = creatorRankings ) - sections.add(growthRankingSection) + sections.add(creatorRankingSection) // 새로 시작 (newCreators) val newCreators = queryRepository diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/GetExplorerResponse.kt b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/GetExplorerResponse.kt index 2d7f4e8..7617809 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/GetExplorerResponse.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/GetExplorerResponse.kt @@ -6,6 +6,7 @@ data class GetExplorerSectionResponse( val title: String, val coloredTitle: String?, val color: String?, + val desc: String? = null, val creators: List )