feat(creator): 채널 홈 조회 정책을 추가한다
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package kr.co.vividnext.sodalive.v2.creator.channel.domain
|
||||
|
||||
import kr.co.vividnext.sodalive.v2.common.domain.CreatorActivityType
|
||||
import java.time.LocalDateTime
|
||||
|
||||
class CreatorChannelHomeQueryPolicy {
|
||||
fun limitSchedules(
|
||||
schedules: List<CreatorChannelSchedule>,
|
||||
now: LocalDateTime
|
||||
): List<CreatorChannelSchedule> {
|
||||
return schedules
|
||||
.filter { it.scheduledAt > now }
|
||||
.sortedWith(compareBy<CreatorChannelSchedule> { it.scheduledAt }.thenBy { it.type.scheduleOrder() })
|
||||
.take(3)
|
||||
}
|
||||
|
||||
fun excludeLatestAudioContent(
|
||||
audioContents: List<CreatorChannelAudioContent>,
|
||||
latestAudioContentId: Long?
|
||||
): List<CreatorChannelAudioContent> {
|
||||
return audioContents.filter { it.audioContentId != latestAudioContentId }
|
||||
}
|
||||
|
||||
fun markFirstAudioContent(audioContents: List<CreatorChannelAudioContent>): List<CreatorChannelAudioContent> {
|
||||
val firstAudioContentId = audioContents
|
||||
.minWithOrNull(compareBy<CreatorChannelAudioContent> { it.publishedAt }.thenBy { it.audioContentId })
|
||||
?.audioContentId
|
||||
|
||||
return audioContents.map { audioContent ->
|
||||
audioContent.copy(isFirstContent = audioContent.audioContentId == firstAudioContentId)
|
||||
}
|
||||
}
|
||||
|
||||
private fun CreatorActivityType.scheduleOrder(): Int {
|
||||
return if (this == CreatorActivityType.LIVE) 0 else 1
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user