feat(home-live): 현재 진행 중 라이브 facade를 추가한다
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
package kr.co.vividnext.sodalive.v2.api.home.live.application
|
||||
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import kr.co.vividnext.sodalive.member.contentpreference.MemberContentPreferenceService
|
||||
import kr.co.vividnext.sodalive.v2.api.home.live.dto.HomeOnAirLivePageResponse
|
||||
import kr.co.vividnext.sodalive.v2.api.home.live.dto.HomeOnAirLiveResponse
|
||||
import kr.co.vividnext.sodalive.v2.recommendation.application.HomeRecommendationQueryService
|
||||
import kr.co.vividnext.sodalive.v2.recommendation.port.out.HomeLiveRecommendationRecord
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.stereotype.Component
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneOffset
|
||||
|
||||
@Component
|
||||
class HomeOnAirLiveFacade(
|
||||
private val queryService: HomeRecommendationQueryService,
|
||||
private val memberContentPreferenceService: MemberContentPreferenceService,
|
||||
@Value("\${cloud.aws.cloud-front.host}")
|
||||
private val cloudFrontHost: String
|
||||
) {
|
||||
fun getOnAirLives(member: Member, page: Int): HomeOnAirLivePageResponse {
|
||||
val normalizedPage = page.coerceIn(0, MAX_PAGE)
|
||||
val fetched = queryService.findLiveRecommendations(
|
||||
offset = normalizedPage * PAGE_SIZE,
|
||||
limit = PAGE_SIZE + 1,
|
||||
memberId = member.id,
|
||||
includeAdultLives = memberContentPreferenceService.canViewAdultContent(member)
|
||||
)
|
||||
val items = fetched.take(PAGE_SIZE).map { it.toResponse() }
|
||||
|
||||
return HomeOnAirLivePageResponse(
|
||||
items = items,
|
||||
page = normalizedPage,
|
||||
size = PAGE_SIZE,
|
||||
hasNext = fetched.size > PAGE_SIZE
|
||||
)
|
||||
}
|
||||
|
||||
private fun HomeLiveRecommendationRecord.toResponse() = HomeOnAirLiveResponse(
|
||||
roomId = liveRoomId,
|
||||
creatorNickname = creatorNickname,
|
||||
creatorProfileImage = profileImageUrl(creatorProfileImage),
|
||||
title = title,
|
||||
price = price,
|
||||
beginDateTimeUtc = beginDateTime.toUtcIso()
|
||||
)
|
||||
|
||||
private fun profileImageUrl(path: String?): String {
|
||||
return imageUrl(path) ?: "$cloudFrontHost/profile/default-profile.png"
|
||||
}
|
||||
|
||||
private fun imageUrl(path: String?): String? {
|
||||
return if (path.isNullOrBlank()) null else "$cloudFrontHost/$path"
|
||||
}
|
||||
|
||||
private fun LocalDateTime.toUtcIso(): String {
|
||||
return atOffset(ZoneOffset.UTC).toInstant().toString()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val PAGE_SIZE = 20
|
||||
private const val MAX_PAGE = 10_000
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user