feat(content): 랭킹 응답 매핑을 추가한다
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package kr.co.vividnext.sodalive.v2.main.content.model
|
||||
|
||||
import kr.co.vividnext.sodalive.v2.main.content.data.AudioRankingItemResponse
|
||||
import kr.co.vividnext.sodalive.v2.main.content.data.AudioRankingResponse
|
||||
import kr.co.vividnext.sodalive.v2.widget.contentranking.ContentRankingItem
|
||||
import kr.co.vividnext.sodalive.v2.widget.ranking.RankingChangeType
|
||||
import kr.co.vividnext.sodalive.v2.widget.ranking.RankingChangeType.Decrease
|
||||
import kr.co.vividnext.sodalive.v2.widget.ranking.RankingChangeType.Increase
|
||||
import kr.co.vividnext.sodalive.v2.widget.ranking.RankingChangeType.New
|
||||
import kr.co.vividnext.sodalive.v2.widget.ranking.RankingChangeType.Stay
|
||||
import kotlin.math.abs
|
||||
|
||||
fun AudioRankingResponse.toContentRankingItems(): List<ContentRankingItem> = items
|
||||
.filter { it.rank >= 1 }
|
||||
.sortedBy { it.rank }
|
||||
.map { it.toContentRankingItem(showRankChange) }
|
||||
|
||||
private fun AudioRankingItemResponse.toContentRankingItem(showRankChange: Boolean): ContentRankingItem {
|
||||
val changeType = toRankingChangeType()
|
||||
return ContentRankingItem(
|
||||
contentId = contentId.toString(),
|
||||
creatorId = "",
|
||||
rank = rank,
|
||||
previousRank = null,
|
||||
rankChangeType = changeType,
|
||||
rankChangeAmount = if (changeType == New) 0 else abs(rankChange ?: 0),
|
||||
contentName = title,
|
||||
creatorName = creatorNickname,
|
||||
imageUrl = coverImageUrl.orEmpty(),
|
||||
isBlocked = false,
|
||||
showRankChange = showRankChange
|
||||
)
|
||||
}
|
||||
|
||||
private fun AudioRankingItemResponse.toRankingChangeType(): RankingChangeType = when {
|
||||
isNew -> New
|
||||
rankChange == null || rankChange == 0 -> Stay
|
||||
rankChange > 0 -> Increase
|
||||
else -> Decrease
|
||||
}
|
||||
Reference in New Issue
Block a user