From b59d7b5dcac2e5576a035bb468693a7a013f6a80 Mon Sep 17 00:00:00 2001 From: Klaus Date: Fri, 13 Oct 2023 23:59:38 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=ED=83=90=EC=83=89=20-=20=EC=9D=B8=EA=B8=B0?= =?UTF-8?q?=20=EA=B8=89=EC=83=81=EC=8A=B9=20=EC=A0=9C=EA=B1=B0,=20?= =?UTF-8?q?=EC=9D=B8=EA=B8=B0=20=ED=81=AC=EB=A6=AC=EC=97=90=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20=EC=84=B9=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sodalive/explorer/CreatorRanking.kt | 22 +++++++++++++++ .../explorer/ExplorerQueryRepository.kt | 25 +++++++---------- .../sodalive/explorer/ExplorerService.kt | 27 ++++++++++++++----- .../sodalive/explorer/GetExplorerResponse.kt | 1 + 4 files changed, 53 insertions(+), 22 deletions(-) create mode 100644 src/main/kotlin/kr/co/vividnext/sodalive/explorer/CreatorRanking.kt 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..5413fee 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,24 @@ class ExplorerService( } .toList() - val growthRankingSection = GetExplorerSectionResponse( - title = "인기 급상승중", + val currentDateTime = LocalDateTime.now() + val lastSunday = currentDateTime + .minusWeeks(1) + .with(TemporalAdjusters.previousOrSame(DayOfWeek.SUNDAY)) + val lastMonday = lastSunday.minusDays(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 ) From a7fc89cf4087cc4c4f09f346df6f71ee5d3bdc04 Mon Sep 17 00:00:00 2001 From: Klaus Date: Sat, 14 Oct 2023 00:24:27 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=ED=83=90=EC=83=89=20=EC=9D=B8=EA=B8=B0=20?= =?UTF-8?q?=ED=81=AC=EB=A6=AC=EC=97=90=EC=9D=B4=ED=84=B0=20=EC=84=B9?= =?UTF-8?q?=EC=85=98=20-=20=EB=82=A0=EC=A7=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kr/co/vividnext/sodalive/explorer/ExplorerService.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 5413fee..64af747 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/ExplorerService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/ExplorerService.kt @@ -68,10 +68,11 @@ class ExplorerService( .toList() val currentDateTime = LocalDateTime.now() - val lastSunday = currentDateTime + val lastMonday = currentDateTime .minusWeeks(1) .with(TemporalAdjusters.previousOrSame(DayOfWeek.SUNDAY)) - val lastMonday = lastSunday.minusDays(6) + val lastSunday = lastMonday + .plusDays(6) val formatter = DateTimeFormatter.ofPattern("MM월 dd일") val formattedLastMonday = lastMonday.format(formatter) From d561ad6d41e73592f2c50da9f0037dc410a4b85d Mon Sep 17 00:00:00 2001 From: Klaus Date: Sat, 14 Oct 2023 00:31:47 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=ED=83=90=EC=83=89=20=EC=9D=B8=EA=B8=B0=20?= =?UTF-8?q?=ED=81=AC=EB=A6=AC=EC=97=90=EC=9D=B4=ED=84=B0=20=EC=84=B9?= =?UTF-8?q?=EC=85=98=20-=20=EB=82=A0=EC=A7=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/kr/co/vividnext/sodalive/explorer/ExplorerService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 64af747..0a752d3 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/ExplorerService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/ExplorerService.kt @@ -70,7 +70,7 @@ class ExplorerService( val currentDateTime = LocalDateTime.now() val lastMonday = currentDateTime .minusWeeks(1) - .with(TemporalAdjusters.previousOrSame(DayOfWeek.SUNDAY)) + .with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)) val lastSunday = lastMonday .plusDays(6)