후원랭킹 기간 선택 반영
크리에이터 본인 조회 시 후원랭킹 기간을 선택하도록 period 파라미터를 제공한다.
This commit is contained in:
@@ -7,6 +7,7 @@ import kr.co.vividnext.sodalive.explorer.profile.PostWriteCheersRequest
|
|||||||
import kr.co.vividnext.sodalive.explorer.profile.PutWriteCheersRequest
|
import kr.co.vividnext.sodalive.explorer.profile.PutWriteCheersRequest
|
||||||
import kr.co.vividnext.sodalive.i18n.LangContext
|
import kr.co.vividnext.sodalive.i18n.LangContext
|
||||||
import kr.co.vividnext.sodalive.i18n.SodaMessageSource
|
import kr.co.vividnext.sodalive.i18n.SodaMessageSource
|
||||||
|
import kr.co.vividnext.sodalive.member.DonationRankingPeriod
|
||||||
import kr.co.vividnext.sodalive.member.Member
|
import kr.co.vividnext.sodalive.member.Member
|
||||||
import org.springframework.data.domain.Pageable
|
import org.springframework.data.domain.Pageable
|
||||||
import org.springframework.security.access.prepost.PreAuthorize
|
import org.springframework.security.access.prepost.PreAuthorize
|
||||||
@@ -75,11 +76,12 @@ class ExplorerController(
|
|||||||
@GetMapping("/profile/{id}/donation-rank")
|
@GetMapping("/profile/{id}/donation-rank")
|
||||||
fun getCreatorProfileDonationRanking(
|
fun getCreatorProfileDonationRanking(
|
||||||
@PathVariable("id") creatorId: Long,
|
@PathVariable("id") creatorId: Long,
|
||||||
|
@RequestParam("period", required = false) period: DonationRankingPeriod? = null,
|
||||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?,
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?,
|
||||||
pageable: Pageable
|
pageable: Pageable
|
||||||
) = run {
|
) = run {
|
||||||
if (member == null) throw SodaException(messageKey = "common.error.bad_credentials")
|
if (member == null) throw SodaException(messageKey = "common.error.bad_credentials")
|
||||||
ApiResponse.ok(service.getCreatorProfileDonationRanking(creatorId, pageable, member))
|
ApiResponse.ok(service.getCreatorProfileDonationRanking(creatorId, period, pageable, member))
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/profile/cheers")
|
@PostMapping("/profile/cheers")
|
||||||
|
|||||||
@@ -399,26 +399,33 @@ class ExplorerService(
|
|||||||
|
|
||||||
fun getCreatorProfileDonationRanking(
|
fun getCreatorProfileDonationRanking(
|
||||||
creatorId: Long,
|
creatorId: Long,
|
||||||
|
period: DonationRankingPeriod?,
|
||||||
pageable: Pageable,
|
pageable: Pageable,
|
||||||
member: Member
|
member: Member
|
||||||
): GetDonationAllResponse {
|
): GetDonationAllResponse {
|
||||||
val creatorAccount = queryRepository.getMember(creatorId)
|
val creatorAccount = queryRepository.getMember(creatorId)
|
||||||
?: throw SodaException(messageKey = "member.validation.user_not_found")
|
?: throw SodaException(messageKey = "member.validation.user_not_found")
|
||||||
val donationRankingPeriod = creatorAccount.donationRankingPeriod ?: DonationRankingPeriod.CUMULATIVE
|
val donationRankingPeriod = creatorAccount.donationRankingPeriod ?: DonationRankingPeriod.CUMULATIVE
|
||||||
|
val isCreatorSelf = creatorId == member.id!!
|
||||||
|
val effectivePeriod = if (isCreatorSelf && period != null) {
|
||||||
|
period
|
||||||
|
} else {
|
||||||
|
donationRankingPeriod
|
||||||
|
}
|
||||||
val currentDate = LocalDate.now().atTime(0, 0, 0)
|
val currentDate = LocalDate.now().atTime(0, 0, 0)
|
||||||
val firstDayOfLastWeek = currentDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)).minusDays(7)
|
val firstDayOfLastWeek = currentDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)).minusDays(7)
|
||||||
val firstDayOfMonth = currentDate.with(TemporalAdjusters.firstDayOfMonth())
|
val firstDayOfMonth = currentDate.with(TemporalAdjusters.firstDayOfMonth())
|
||||||
|
|
||||||
val donationMemberTotal = donationRankingService.getMemberDonationRankingTotal(
|
val donationMemberTotal = donationRankingService.getMemberDonationRankingTotal(
|
||||||
creatorId,
|
creatorId,
|
||||||
donationRankingPeriod
|
effectivePeriod
|
||||||
)
|
)
|
||||||
val donationRanking = donationRankingService.getMemberDonationRanking(
|
val donationRanking = donationRankingService.getMemberDonationRanking(
|
||||||
creatorId = creatorId,
|
creatorId = creatorId,
|
||||||
offset = pageable.offset,
|
offset = pageable.offset,
|
||||||
limit = pageable.pageSize.toLong(),
|
limit = pageable.pageSize.toLong(),
|
||||||
withDonationCan = creatorId == member.id!!,
|
withDonationCan = isCreatorSelf,
|
||||||
period = donationRankingPeriod
|
period = effectivePeriod
|
||||||
)
|
)
|
||||||
|
|
||||||
return GetDonationAllResponse(
|
return GetDonationAllResponse(
|
||||||
|
|||||||
Reference in New Issue
Block a user