refactor(creator): 시리즈 subtitle 모델을 분리한다
This commit is contained in:
@@ -2,10 +2,6 @@ package kr.co.vividnext.sodalive.v2.creator.channel.series.model
|
||||
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.series.data.CreatorChannelSeriesResponse
|
||||
|
||||
private const val BULLET_SEPARATOR = " • "
|
||||
private const val STATUS_PROCEEDING = "연재"
|
||||
private const val STATUS_COMPLETED = "완결"
|
||||
|
||||
fun List<CreatorChannelSeriesResponse>.toSeriesItemUiModels(
|
||||
isOwner: Boolean
|
||||
): List<CreatorChannelSeriesItemUiModel> = mapNotNull { it.toSeriesItemUiModel(isOwner) }
|
||||
@@ -16,7 +12,7 @@ private fun CreatorChannelSeriesResponse.toSeriesItemUiModel(isOwner: Boolean):
|
||||
return CreatorChannelSeriesItemUiModel(
|
||||
seriesId = seriesId,
|
||||
title = title,
|
||||
subtitle = subtitle(),
|
||||
subtitle = toSubtitleUiModel(),
|
||||
coverImageUrl = coverImageUrl,
|
||||
showOriginalTag = isOriginal,
|
||||
showAdultBadge = isAdult,
|
||||
@@ -24,11 +20,13 @@ private fun CreatorChannelSeriesResponse.toSeriesItemUiModel(isOwner: Boolean):
|
||||
)
|
||||
}
|
||||
|
||||
private fun CreatorChannelSeriesResponse.subtitle(): String = listOfNotNull(
|
||||
publishedDaysOfWeek?.takeIf { it.isNotBlank() },
|
||||
"총 ${contentCount}화",
|
||||
if (isProceeding) STATUS_PROCEEDING else STATUS_COMPLETED
|
||||
).joinToString(BULLET_SEPARATOR)
|
||||
private fun CreatorChannelSeriesResponse.toSubtitleUiModel(): CreatorChannelSeriesSubtitleUiModel {
|
||||
return CreatorChannelSeriesSubtitleUiModel(
|
||||
publishedDaysOfWeek = publishedDaysOfWeek?.takeIf { it.isNotBlank() },
|
||||
contentCount = contentCount,
|
||||
isProceeding = isProceeding
|
||||
)
|
||||
}
|
||||
|
||||
private fun CreatorChannelSeriesResponse.toProgressUiModel(isOwner: Boolean): CreatorChannelSeriesProgressUiModel? {
|
||||
if (isOwner) return null
|
||||
|
||||
@@ -3,13 +3,19 @@ package kr.co.vividnext.sodalive.v2.creator.channel.series.model
|
||||
data class CreatorChannelSeriesItemUiModel(
|
||||
val seriesId: Long,
|
||||
val title: String,
|
||||
val subtitle: String,
|
||||
val subtitle: CreatorChannelSeriesSubtitleUiModel,
|
||||
val coverImageUrl: String?,
|
||||
val showOriginalTag: Boolean,
|
||||
val showAdultBadge: Boolean,
|
||||
val progress: CreatorChannelSeriesProgressUiModel?
|
||||
)
|
||||
|
||||
data class CreatorChannelSeriesSubtitleUiModel(
|
||||
val publishedDaysOfWeek: String?,
|
||||
val contentCount: Int,
|
||||
val isProceeding: Boolean
|
||||
)
|
||||
|
||||
data class CreatorChannelSeriesProgressUiModel(
|
||||
val purchasedCount: Int,
|
||||
val paidCount: Int,
|
||||
|
||||
@@ -11,35 +11,39 @@ import org.junit.Test
|
||||
class CreatorChannelSeriesMapperTest {
|
||||
|
||||
@Test
|
||||
fun `isProceeding true이면 subtitle에 연재가 포함된다`() {
|
||||
fun `isProceeding true이면 subtitle status가 proceeding이다`() {
|
||||
val item = listOf(series(isProceeding = true)).toSeriesItemUiModels(isOwner = false).single()
|
||||
|
||||
assertTrue(item.subtitle.contains("연재"))
|
||||
assertEquals(true, item.subtitle.isProceeding)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `isProceeding false이면 subtitle에 완결이 포함된다`() {
|
||||
fun `isProceeding false이면 subtitle status가 completed이다`() {
|
||||
val item = listOf(series(isProceeding = false)).toSeriesItemUiModels(isOwner = false).single()
|
||||
|
||||
assertTrue(item.subtitle.contains("완결"))
|
||||
assertEquals(false, item.subtitle.isProceeding)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `publishedDaysOfWeek contentCount 진행 상태를 bullet 형식으로 조합한다`() {
|
||||
fun `publishedDaysOfWeek contentCount 진행 상태를 subtitle 조각으로 유지한다`() {
|
||||
val item = listOf(
|
||||
series(publishedDaysOfWeek = "매주 월", contentCount = 45, isProceeding = true)
|
||||
).toSeriesItemUiModels(isOwner = false).single()
|
||||
|
||||
assertEquals("매주 월 • 총 45화 • 연재", item.subtitle)
|
||||
assertEquals("매주 월", item.subtitle.publishedDaysOfWeek)
|
||||
assertEquals(45, item.subtitle.contentCount)
|
||||
assertEquals(true, item.subtitle.isProceeding)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `publishedDaysOfWeek가 blank이면 빈 bullet 없이 조합한다`() {
|
||||
fun `publishedDaysOfWeek가 blank이면 subtitle 조각에서 제외한다`() {
|
||||
val item = listOf(
|
||||
series(publishedDaysOfWeek = " ", contentCount = 45, isProceeding = true)
|
||||
).toSeriesItemUiModels(isOwner = false).single()
|
||||
|
||||
assertEquals("총 45화 • 연재", item.subtitle)
|
||||
assertNull(item.subtitle.publishedDaysOfWeek)
|
||||
assertEquals(45, item.subtitle.contentCount)
|
||||
assertEquals(true, item.subtitle.isProceeding)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user