test #384
@@ -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.i18n.LangContext
|
||||
import kr.co.vividnext.sodalive.i18n.SodaMessageSource
|
||||
import kr.co.vividnext.sodalive.member.DonationRankingPeriod
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import org.springframework.data.domain.Pageable
|
||||
import org.springframework.security.access.prepost.PreAuthorize
|
||||
@@ -75,11 +76,12 @@ class ExplorerController(
|
||||
@GetMapping("/profile/{id}/donation-rank")
|
||||
fun getCreatorProfileDonationRanking(
|
||||
@PathVariable("id") creatorId: Long,
|
||||
@RequestParam("period", required = false) period: DonationRankingPeriod? = null,
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?,
|
||||
pageable: Pageable
|
||||
) = run {
|
||||
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")
|
||||
|
||||
@@ -399,26 +399,33 @@ class ExplorerService(
|
||||
|
||||
fun getCreatorProfileDonationRanking(
|
||||
creatorId: Long,
|
||||
period: DonationRankingPeriod?,
|
||||
pageable: Pageable,
|
||||
member: Member
|
||||
): GetDonationAllResponse {
|
||||
val creatorAccount = queryRepository.getMember(creatorId)
|
||||
?: throw SodaException(messageKey = "member.validation.user_not_found")
|
||||
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 firstDayOfLastWeek = currentDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)).minusDays(7)
|
||||
val firstDayOfMonth = currentDate.with(TemporalAdjusters.firstDayOfMonth())
|
||||
|
||||
val donationMemberTotal = donationRankingService.getMemberDonationRankingTotal(
|
||||
creatorId,
|
||||
donationRankingPeriod
|
||||
effectivePeriod
|
||||
)
|
||||
val donationRanking = donationRankingService.getMemberDonationRanking(
|
||||
creatorId = creatorId,
|
||||
offset = pageable.offset,
|
||||
limit = pageable.pageSize.toLong(),
|
||||
withDonationCan = creatorId == member.id!!,
|
||||
period = donationRankingPeriod
|
||||
withDonationCan = isCreatorSelf,
|
||||
period = effectivePeriod
|
||||
)
|
||||
|
||||
return GetDonationAllResponse(
|
||||
|
||||
Reference in New Issue
Block a user