feat(content): 콘텐츠 전체보기 응답 모델을 추가한다
This commit is contained in:
@@ -0,0 +1,76 @@
|
|||||||
|
package kr.co.vividnext.sodalive.v2.api.content.overview.dto
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
|
import kr.co.vividnext.sodalive.v2.content.recommendation.domain.AudioCard
|
||||||
|
import kr.co.vividnext.sodalive.v2.recommendation.port.out.HomeFirstAudioContentRecord
|
||||||
|
|
||||||
|
data class ContentOverviewPageResponse(
|
||||||
|
val type: ContentOverviewType,
|
||||||
|
val items: List<ContentOverviewItemResponse>,
|
||||||
|
val page: Int,
|
||||||
|
val size: Int,
|
||||||
|
@JsonProperty("hasNext")
|
||||||
|
val hasNext: Boolean
|
||||||
|
)
|
||||||
|
|
||||||
|
enum class ContentOverviewType {
|
||||||
|
NEW_AND_HOT_AUDIO,
|
||||||
|
FIRST_AUDIO_CONTENT;
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun from(value: String?): ContentOverviewType {
|
||||||
|
return values().firstOrNull { it.name == value } ?: NEW_AND_HOT_AUDIO
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class ContentOverviewItemResponse(
|
||||||
|
val contentId: Long,
|
||||||
|
val title: String,
|
||||||
|
val coverImage: String?,
|
||||||
|
val price: Int,
|
||||||
|
@JsonProperty("isPointAvailable")
|
||||||
|
val isPointAvailable: Boolean,
|
||||||
|
val creatorNickname: String,
|
||||||
|
@JsonProperty("isAdult")
|
||||||
|
val isAdult: Boolean,
|
||||||
|
@JsonProperty("isFirstContent")
|
||||||
|
val isFirstContent: Boolean,
|
||||||
|
@JsonProperty("isOriginalSeries")
|
||||||
|
val isOriginalSeries: Boolean
|
||||||
|
) {
|
||||||
|
companion object {
|
||||||
|
fun fromNewAndHot(audio: AudioCard): ContentOverviewItemResponse {
|
||||||
|
return ContentOverviewItemResponse(
|
||||||
|
contentId = audio.audioContentId,
|
||||||
|
title = audio.title,
|
||||||
|
coverImage = audio.imageUrl,
|
||||||
|
price = audio.price,
|
||||||
|
isPointAvailable = audio.isPointAvailable,
|
||||||
|
creatorNickname = audio.creatorNickname,
|
||||||
|
isAdult = audio.isAdult,
|
||||||
|
isFirstContent = audio.isFirstContent,
|
||||||
|
isOriginalSeries = audio.isOriginalSeries
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun fromFirstAudioContent(
|
||||||
|
audio: HomeFirstAudioContentRecord,
|
||||||
|
coverImage: String?,
|
||||||
|
isAdult: Boolean,
|
||||||
|
isOriginalSeries: Boolean
|
||||||
|
): ContentOverviewItemResponse {
|
||||||
|
return ContentOverviewItemResponse(
|
||||||
|
contentId = audio.contentId,
|
||||||
|
title = audio.title,
|
||||||
|
coverImage = coverImage,
|
||||||
|
price = audio.price,
|
||||||
|
isPointAvailable = audio.isPointAvailable,
|
||||||
|
creatorNickname = audio.creatorNickname,
|
||||||
|
isAdult = isAdult,
|
||||||
|
isFirstContent = true,
|
||||||
|
isOriginalSeries = isOriginalSeries
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package kr.co.vividnext.sodalive.v2.api.content.overview.dto
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||||
|
import kr.co.vividnext.sodalive.v2.recommendation.port.out.HomeFirstAudioContentRecord
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.DisplayName
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
class ContentOverviewPageResponseTest {
|
||||||
|
private val objectMapper = jacksonObjectMapper()
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("콘텐츠 전체보기 응답은 공개 JSON 필드명만 직렬화한다")
|
||||||
|
fun shouldSerializeContentOverviewPageResponse() {
|
||||||
|
val response = ContentOverviewPageResponse(
|
||||||
|
type = ContentOverviewType.NEW_AND_HOT_AUDIO,
|
||||||
|
items = listOf(
|
||||||
|
ContentOverviewItemResponse(
|
||||||
|
contentId = 1L,
|
||||||
|
title = "audio",
|
||||||
|
coverImage = "https://cdn.test/audio.png",
|
||||||
|
price = 10,
|
||||||
|
isPointAvailable = true,
|
||||||
|
creatorNickname = "creator",
|
||||||
|
isAdult = false,
|
||||||
|
isFirstContent = true,
|
||||||
|
isOriginalSeries = false
|
||||||
|
)
|
||||||
|
),
|
||||||
|
page = 0,
|
||||||
|
size = 20,
|
||||||
|
hasNext = true
|
||||||
|
)
|
||||||
|
|
||||||
|
val json = objectMapper.readTree(objectMapper.writeValueAsString(response))
|
||||||
|
|
||||||
|
assertEquals("NEW_AND_HOT_AUDIO", json["type"].asText())
|
||||||
|
assertEquals(true, json["hasNext"].asBoolean())
|
||||||
|
assertEquals(1L, json["items"][0]["contentId"].asLong())
|
||||||
|
assertEquals("https://cdn.test/audio.png", json["items"][0]["coverImage"].asText())
|
||||||
|
assertEquals(true, json["items"][0]["isPointAvailable"].asBoolean())
|
||||||
|
assertEquals(false, json["items"][0]["isAdult"].asBoolean())
|
||||||
|
assertEquals(true, json["items"][0]["isFirstContent"].asBoolean())
|
||||||
|
assertEquals(false, json["items"][0]["isOriginalSeries"].asBoolean())
|
||||||
|
assertEquals(false, json["items"][0].has("audioContentId"))
|
||||||
|
assertEquals(false, json["items"][0].has("imageUrl"))
|
||||||
|
assertEquals(false, json["items"][0].has("duration"))
|
||||||
|
assertEquals(false, json["items"][0].has("creatorId"))
|
||||||
|
assertEquals(false, json["items"][0].has("creatorProfileImage"))
|
||||||
|
assertEquals(false, json["items"][0].has("pointAvailable"))
|
||||||
|
assertEquals(false, json["items"][0].has("adult"))
|
||||||
|
assertEquals(false, json["items"][0].has("firstContent"))
|
||||||
|
assertEquals(false, json["items"][0].has("originalSeries"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("첫 번째 오디오 콘텐츠 변환은 성인/오리지널 플래그를 전달한다")
|
||||||
|
fun shouldMapFirstAudioContentFlags() {
|
||||||
|
val response = ContentOverviewItemResponse.fromFirstAudioContent(
|
||||||
|
audio = HomeFirstAudioContentRecord(
|
||||||
|
contentId = 1L,
|
||||||
|
creatorId = 10L,
|
||||||
|
creatorNickname = "creator",
|
||||||
|
creatorProfileImage = null,
|
||||||
|
title = "first audio",
|
||||||
|
price = 100,
|
||||||
|
coverImage = "cover/audio.png",
|
||||||
|
isPointAvailable = true
|
||||||
|
),
|
||||||
|
coverImage = "https://cdn.test/cover/audio.png",
|
||||||
|
isAdult = true,
|
||||||
|
isOriginalSeries = true
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(true, response.isAdult)
|
||||||
|
assertEquals(true, response.isOriginalSeries)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user