feat(creator-channel): 시리즈 탭 조회 정책을 추가한다
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
package kr.co.vividnext.sodalive.v2.creator.channel.series.domain
|
||||
|
||||
import kr.co.vividnext.sodalive.creator.admin.content.series.SeriesPublishedDaysOfWeek
|
||||
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 CreatorChannelSeriesQueryPolicy {
|
||||
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(paidContentCount: Int, purchasedContentCount: Int): Int {
|
||||
if (paidContentCount == 0) {
|
||||
return 0
|
||||
}
|
||||
return purchasedContentCount * 100 / paidContentCount
|
||||
}
|
||||
|
||||
fun publishedDaysOfWeekText(days: Set<SeriesPublishedDaysOfWeek>, locale: String): String {
|
||||
if (days.contains(SeriesPublishedDaysOfWeek.RANDOM)) {
|
||||
return randomText(locale)
|
||||
}
|
||||
if (days.containsAll(WEEKDAYS)) {
|
||||
return everyDayText(locale)
|
||||
}
|
||||
|
||||
val dayText = WEEKDAYS
|
||||
.filter(days::contains)
|
||||
.joinToString(", ") { dayText(it, locale) }
|
||||
|
||||
return weeklyText(dayText, locale)
|
||||
}
|
||||
|
||||
private fun randomText(locale: String): String {
|
||||
return when (locale) {
|
||||
"en" -> "Random"
|
||||
"ja" -> "ランダム"
|
||||
else -> "랜덤"
|
||||
}
|
||||
}
|
||||
|
||||
private fun everyDayText(locale: String): String {
|
||||
return when (locale) {
|
||||
"en" -> "Every day"
|
||||
"ja" -> "毎日"
|
||||
else -> "매일"
|
||||
}
|
||||
}
|
||||
|
||||
private fun weeklyText(dayText: String, locale: String): String {
|
||||
return when (locale) {
|
||||
"en" -> "Every $dayText"
|
||||
"ja" -> "毎週 $dayText"
|
||||
else -> "매주 $dayText"
|
||||
}
|
||||
}
|
||||
|
||||
private fun dayText(day: SeriesPublishedDaysOfWeek, locale: String): String {
|
||||
return when (locale) {
|
||||
"en" -> EN_DAY_TEXTS.getValue(day)
|
||||
"ja" -> JA_DAY_TEXTS.getValue(day)
|
||||
else -> KO_DAY_TEXTS.getValue(day)
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
private val WEEKDAYS = listOf(
|
||||
SeriesPublishedDaysOfWeek.SUN,
|
||||
SeriesPublishedDaysOfWeek.MON,
|
||||
SeriesPublishedDaysOfWeek.TUE,
|
||||
SeriesPublishedDaysOfWeek.WED,
|
||||
SeriesPublishedDaysOfWeek.THU,
|
||||
SeriesPublishedDaysOfWeek.FRI,
|
||||
SeriesPublishedDaysOfWeek.SAT
|
||||
)
|
||||
private val KO_DAY_TEXTS = mapOf(
|
||||
SeriesPublishedDaysOfWeek.SUN to "일",
|
||||
SeriesPublishedDaysOfWeek.MON to "월",
|
||||
SeriesPublishedDaysOfWeek.TUE to "화",
|
||||
SeriesPublishedDaysOfWeek.WED to "수",
|
||||
SeriesPublishedDaysOfWeek.THU to "목",
|
||||
SeriesPublishedDaysOfWeek.FRI to "금",
|
||||
SeriesPublishedDaysOfWeek.SAT to "토"
|
||||
)
|
||||
private val EN_DAY_TEXTS = mapOf(
|
||||
SeriesPublishedDaysOfWeek.SUN to "Sun",
|
||||
SeriesPublishedDaysOfWeek.MON to "Mon",
|
||||
SeriesPublishedDaysOfWeek.TUE to "Tue",
|
||||
SeriesPublishedDaysOfWeek.WED to "Wed",
|
||||
SeriesPublishedDaysOfWeek.THU to "Thu",
|
||||
SeriesPublishedDaysOfWeek.FRI to "Fri",
|
||||
SeriesPublishedDaysOfWeek.SAT to "Sat"
|
||||
)
|
||||
private val JA_DAY_TEXTS = mapOf(
|
||||
SeriesPublishedDaysOfWeek.SUN to "日",
|
||||
SeriesPublishedDaysOfWeek.MON to "月",
|
||||
SeriesPublishedDaysOfWeek.TUE to "火",
|
||||
SeriesPublishedDaysOfWeek.WED to "水",
|
||||
SeriesPublishedDaysOfWeek.THU to "木",
|
||||
SeriesPublishedDaysOfWeek.FRI to "金",
|
||||
SeriesPublishedDaysOfWeek.SAT to "土"
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user