From c4d9d503ac604129fdee12c75923fadb2c263fec Mon Sep 17 00:00:00 2001 From: Klaus Date: Sun, 5 Jan 2025 15:35:26 +0900 Subject: [PATCH] =?UTF-8?q?=ED=83=90=EC=83=89=EC=97=90=20=EC=9E=88?= =?UTF-8?q?=EB=8A=94=20=ED=81=AC=EB=A6=AC=EC=97=90=EC=9D=B4=ED=84=B0=20?= =?UTF-8?q?=EB=9E=AD=ED=82=B9=EA=B3=BC=20=EB=8F=99=EC=9D=BC=ED=95=9C=20?= =?UTF-8?q?=EB=B3=84=EB=8F=84=EC=9D=98=20API=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sodalive/explorer/ExplorerController.kt | 9 ++++++ .../sodalive/explorer/ExplorerService.kt | 28 +++++++++++++++++++ 2 files changed, 37 insertions(+) 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()