From afb64eb8f2dfe7a7f227b6824db4571341c39e06 Mon Sep 17 00:00:00 2001 From: Klaus Date: Sat, 22 Feb 2025 04:09:03 +0900 Subject: [PATCH] =?UTF-8?q?=EB=A9=94=EC=9D=B8=20=EC=8B=9C=EB=A6=AC?= =?UTF-8?q?=EC=A6=88=20=ED=83=AD=20-=20=EC=99=84=EA=B2=B0=20=EC=8B=9C?= =?UTF-8?q?=EB=A6=AC=EC=A6=88=20-=201~10=EC=9D=BC,=2011~20=EC=9D=BC,=2021~?= =?UTF-8?q?=ED=95=B4=EB=8B=B9=20=EC=9B=94=EC=9D=98=20=EB=A7=88=EC=A7=80?= =?UTF-8?q?=EB=A7=89=EB=82=A0=20=EB=A1=9C=203=EB=93=B1=EB=B6=84=20?= =?UTF-8?q?=ED=95=98=EC=97=AC=20=EC=88=9C=EC=9C=84=EB=A5=BC=20=EA=B3=84?= =?UTF-8?q?=EC=82=B0=ED=95=98=EA=B3=A0=2010=EC=9D=BC=EC=94=A9=20=EB=B0=98?= =?UTF-8?q?=EC=98=81=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95=20ex)?= =?UTF-8?q?=EC=98=A4=EB=8A=98=EC=9D=B4=2023=EC=9D=BC=20=EC=9D=B4=EB=A9=B4?= =?UTF-8?q?=2011~20=EC=9D=BC=20=EC=82=AC=EC=9D=B4=EC=97=90=20=ED=8C=94?= =?UTF-8?q?=EB=A6=B0=20=EA=B0=9C=EC=88=98=EB=A5=BC=20=EA=B8=B0=EC=A4=80?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=88=9C=EC=9C=84=20=EA=B3=84=EC=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AudioContentMainTabSeriesController.kt | 6 +-- .../AudioContentMainTabSeriesService.kt | 43 ++++++++++++++----- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/content/main/tab/series/AudioContentMainTabSeriesController.kt b/src/main/kotlin/kr/co/vividnext/sodalive/content/main/tab/series/AudioContentMainTabSeriesController.kt index e9577a0..df62807 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/content/main/tab/series/AudioContentMainTabSeriesController.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/content/main/tab/series/AudioContentMainTabSeriesController.kt @@ -39,15 +39,15 @@ class AudioContentMainTabSeriesController(private val service: AudioContentMainT ) } - @GetMapping("/completed-monthly-rank") - fun getRankMonthlyCompletedSeriesList( + @GetMapping("/completed-rank") + fun getRank10DaysCompletedSeriesList( @AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?, pageable: Pageable ) = run { if (member == null) throw SodaException("로그인 정보를 확인해주세요.") ApiResponse.ok( - service.getRankMonthlyCompletedSeriesList( + service.getRank10DaysCompletedSeriesList( memberId = member.id!!, isAdult = member.auth != null, offset = pageable.offset, diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/content/main/tab/series/AudioContentMainTabSeriesService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/content/main/tab/series/AudioContentMainTabSeriesService.kt index 44d256f..58ade63 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/content/main/tab/series/AudioContentMainTabSeriesService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/content/main/tab/series/AudioContentMainTabSeriesService.kt @@ -10,7 +10,9 @@ import kr.co.vividnext.sodalive.member.Member import kr.co.vividnext.sodalive.rank.RankingService import org.springframework.stereotype.Service import java.time.DayOfWeek +import java.time.LocalDate import java.time.LocalDateTime +import java.time.YearMonth import java.time.temporal.TemporalAdjusters @Service @@ -168,20 +170,13 @@ class AudioContentMainTabSeriesService( return GetSeriesListResponse(totalCount, items) } - fun getRankMonthlyCompletedSeriesList( + fun getRank10DaysCompletedSeriesList( memberId: Long, isAdult: Boolean, offset: Long, limit: Long ): GetSeriesListResponse { - val monthlyRankingStartDate = LocalDateTime.now() - .withDayOfMonth(1) - .withHour(15) - .withMinute(0) - .withSecond(0) - .minusDays(1) - val monthlyRankingEndDate = monthlyRankingStartDate - .plusMonths(1) + val (startDate, endDate) = calculateStartAndEndDate() val totalCount = rankingService.getCompleteSeriesRankingTotalCount( memberId = memberId, @@ -191,8 +186,8 @@ class AudioContentMainTabSeriesService( val items = rankingService.getCompleteSeriesRanking( memberId = memberId, isAdult = isAdult, - startDate = monthlyRankingStartDate, - endDate = monthlyRankingEndDate, + startDate = startDate, + endDate = endDate, offset = offset, limit = limit ) @@ -218,4 +213,30 @@ class AudioContentMainTabSeriesService( isAdult = isAdult ) } + + private fun calculateStartAndEndDate(today: LocalDate = LocalDate.now()): Pair { + val yearMonth = YearMonth.from(today) + val lastDayOfMonth = yearMonth.lengthOfMonth() + + return when (today.dayOfMonth) { + in 11..20 -> Pair( + today.withDayOfMonth(1).minusDays(1).atTime(15, 0), + today.withDayOfMonth(10).atTime(15, 0) + ) + + in 21..lastDayOfMonth -> Pair( + today.withDayOfMonth(10).atTime(15, 0), + today.withDayOfMonth(20).atTime(15, 0) + ) + + else -> { + val previousMonth = yearMonth.minusMonths(1) + val lastDayOfPreviousMonth = previousMonth.lengthOfMonth() + Pair( + LocalDate.of(previousMonth.year, previousMonth.month, 20).atTime(15, 0), + LocalDate.of(previousMonth.year, previousMonth.month, lastDayOfPreviousMonth).atTime(15, 0) + ) + } + } + } } -- 2.40.1