diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/ExplorerController.kt b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/ExplorerController.kt index 8b66af3..feb7daa 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/ExplorerController.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/ExplorerController.kt @@ -21,6 +21,15 @@ import org.springframework.web.bind.annotation.RestController @RestController @RequestMapping("/explorer") class ExplorerController(private val service: ExplorerService) { + @GetMapping("/creator-rank") + fun getCreatorRank( + @AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member? + ) = run { + if (member == null) throw SodaException("로그인 정보를 확인해주세요.") + + ApiResponse.ok(service.getCreatorRank(memberId = member.id!!)) + } + @GetMapping fun getExplorer( @AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member? 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 1ce31f5..7c3c8ce 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/ExplorerService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/ExplorerService.kt @@ -47,6 +47,34 @@ class ExplorerService( @Value("\${cloud.aws.cloud-front.host}") private val cloudFrontHost: String ) { + fun getCreatorRank(memberId: Long): GetExplorerSectionResponse { + val creatorRankings = queryRepository + .getCreatorRankings() + .filter { !memberService.isBlocked(blockedMemberId = memberId, memberId = it.id!!) } + .map { it.toExplorerSectionCreator(cloudFrontHost) } + + val currentDateTime = LocalDateTime.now() + val lastMonday = currentDateTime + .minusWeeks(1) + .with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)) + val lastSunday = lastMonday + .plusDays(6) + + val startDateFormatter = DateTimeFormatter.ofPattern("yyyy년 MM월 dd일") + val endDateFormatter = DateTimeFormatter.ofPattern("MM월 dd일") + + val formattedLastMonday = lastMonday.format(startDateFormatter) + val formattedLastSunday = lastSunday.format(endDateFormatter) + + return GetExplorerSectionResponse( + title = "인기 크리에이터", + coloredTitle = "인기", + color = "FF5C49", + desc = "$formattedLastMonday ~ $formattedLastSunday", + creators = creatorRankings + ) + } + fun getExplorer(member: Member, growthRankingCreatorsLimit: Long = 20): GetExplorerResponse { val sections = mutableListOf()