feat(creator-channel): 오디오 탭 조회 정책을 추가한다
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package kr.co.vividnext.sodalive.v2.creator.channel.audio.domain
|
||||
|
||||
import kr.co.vividnext.sodalive.v2.common.domain.ContentSort
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.live.domain.CreatorChannelPage
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Component
|
||||
class CreatorChannelAudioQueryPolicy {
|
||||
fun resolveSort(sort: String?): ContentSort {
|
||||
return runCatching { ContentSort.valueOf(sort ?: ContentSort.LATEST.name) }
|
||||
.getOrDefault(ContentSort.LATEST)
|
||||
}
|
||||
|
||||
fun createPage(page: Int?, size: Int?): CreatorChannelPage {
|
||||
return CreatorChannelPage(
|
||||
page = page?.coerceAtLeast(MIN_PAGE) ?: DEFAULT_PAGE,
|
||||
size = size?.coerceIn(MIN_PAGE_SIZE, MAX_PAGE_SIZE) ?: DEFAULT_PAGE_SIZE
|
||||
)
|
||||
}
|
||||
|
||||
fun <T> limitItems(fetched: List<T>, page: CreatorChannelPage): List<T> {
|
||||
return fetched.take(page.size)
|
||||
}
|
||||
|
||||
fun hasNext(fetched: List<*>, page: CreatorChannelPage): Boolean {
|
||||
return fetched.size > page.size
|
||||
}
|
||||
|
||||
fun purchaseRate(paidAudioContentCount: Int, purchasedAudioContentCount: Int): Double {
|
||||
if (paidAudioContentCount == 0) {
|
||||
return 0.0
|
||||
}
|
||||
return purchasedAudioContentCount.toDouble() / paidAudioContentCount * 100
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val DEFAULT_PAGE = 0
|
||||
private const val DEFAULT_PAGE_SIZE = 20
|
||||
private const val MIN_PAGE = 0
|
||||
private const val MIN_PAGE_SIZE = 20
|
||||
private const val MAX_PAGE_SIZE = 50
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user