탐색에 있는 크리에이터 랭킹과 동일한 별도의 API 생성
This commit is contained in:
parent
824cd2f3ea
commit
c4d9d503ac
|
@ -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?
|
||||
|
|
|
@ -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<GetExplorerSectionResponse>()
|
||||
|
||||
|
|
Loading…
Reference in New Issue