feat(creator): 채널 라이브 탭 조회 API를 추가한다

This commit is contained in:
2026-06-17 20:19:48 +09:00
parent f78772b613
commit 85a331c28d
2 changed files with 259 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
package kr.co.vividnext.sodalive.v2.api.creator.channel.live.adapter.`in`.web
import kr.co.vividnext.sodalive.common.ApiResponse
import kr.co.vividnext.sodalive.common.SodaException
import kr.co.vividnext.sodalive.member.Member
import kr.co.vividnext.sodalive.v2.api.creator.channel.live.application.CreatorChannelLiveFacade
import kr.co.vividnext.sodalive.v2.common.domain.ContentSort
import org.springframework.security.core.annotation.AuthenticationPrincipal
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
@RestController
@RequestMapping("/api/v2/creator-channels")
class CreatorChannelLiveController(
private val creatorChannelLiveFacade: CreatorChannelLiveFacade
) {
@GetMapping("/{creatorId}/live")
fun getLiveTab(
@PathVariable creatorId: Long,
@RequestParam(defaultValue = "LATEST") sort: ContentSort,
@RequestParam(defaultValue = "0") page: Int,
@RequestParam(defaultValue = "20") size: Int,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
ApiResponse.ok(
creatorChannelLiveFacade.getLiveTab(
creatorId = creatorId,
viewer = requireMember(member),
sort = sort,
page = page,
size = size
)
)
}
private fun requireMember(member: Member?): Member {
return member ?: throw SodaException(messageKey = "common.error.bad_credentials")
}
}

View File

@@ -0,0 +1,217 @@
package kr.co.vividnext.sodalive.v2.api.creator.channel.live.adapter.`in`.web
import kr.co.vividnext.sodalive.common.CountryContext
import kr.co.vividnext.sodalive.i18n.LangContext
import kr.co.vividnext.sodalive.i18n.SodaMessageSource
import kr.co.vividnext.sodalive.member.Member
import kr.co.vividnext.sodalive.member.MemberAdapter
import kr.co.vividnext.sodalive.member.MemberRole
import kr.co.vividnext.sodalive.v2.api.creator.channel.live.application.CreatorChannelLiveFacade
import kr.co.vividnext.sodalive.v2.api.creator.channel.live.dto.CreatorChannelAudioContentResponse
import kr.co.vividnext.sodalive.v2.api.creator.channel.live.dto.CreatorChannelLiveResponse
import kr.co.vividnext.sodalive.v2.api.creator.channel.live.dto.CreatorChannelLiveTabResponse
import kr.co.vividnext.sodalive.v2.common.domain.ContentSort
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.mockito.Mockito
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
import org.springframework.boot.test.context.TestConfiguration
import org.springframework.boot.test.mock.mockito.MockBean
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Import
import org.springframework.http.HttpStatus
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.anonymous
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user
import org.springframework.security.web.SecurityFilterChain
import org.springframework.security.web.authentication.HttpStatusEntryPoint
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
import java.time.LocalDateTime
import javax.servlet.http.HttpServletResponse
@WebMvcTest(CreatorChannelLiveController::class)
@Import(CreatorChannelLiveControllerTest.TestSecurityConfig::class)
class CreatorChannelLiveControllerTest @Autowired constructor(
private val mockMvc: MockMvc
) {
@MockBean
private lateinit var facade: CreatorChannelLiveFacade
@MockBean
private lateinit var countryContext: CountryContext
@MockBean
private lateinit var langContext: LangContext
@MockBean
private lateinit var sodaMessageSource: SodaMessageSource
@TestConfiguration
class TestSecurityConfig {
@Bean
fun securityFilterChain(http: HttpSecurity): SecurityFilterChain {
return http
.csrf().disable()
.authorizeRequests()
.anyRequest().authenticated()
.and()
.exceptionHandling()
.authenticationEntryPoint(HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED))
.accessDeniedHandler { _, response, _ -> response.sendError(HttpServletResponse.SC_FORBIDDEN) }
.and()
.build()
}
}
@Test
@DisplayName("크리에이터 채널 라이브 탭 조회는 비회원 요청을 거부한다")
fun shouldRejectAnonymousCreatorChannelLiveRequest() {
mockMvc.perform(
get("/api/v2/creator-channels/1/live")
.with(anonymous())
)
.andExpect(status().isUnauthorized)
}
@Test
@DisplayName("크리에이터 채널 라이브 탭 조회는 기본 정렬과 page 정보를 facade에 전달하고 성공 응답을 반환한다")
fun shouldReturnCreatorChannelLiveTabForAuthenticatedMember() {
val viewer = createMember(id = 10L)
Mockito.doReturn(createResponse()).`when`(facade).getLiveTab(
eqValue(1L),
eqValue(viewer),
eqValue(ContentSort.LATEST),
eqValue(0),
eqValue(20),
anyValue(LocalDateTime.now())
)
mockMvc.perform(
get("/api/v2/creator-channels/1/live")
.with(user(MemberAdapter(viewer)))
)
.andExpect(status().isOk)
.andExpect(jsonPath("$.success").value(true))
.andExpect(jsonPath("$.data.liveReplayContentCount").value(1))
.andExpect(jsonPath("$.data.currentLive").exists())
.andExpect(jsonPath("$.data.liveReplayContents").isArray)
.andExpect(jsonPath("$.data.sort").value("LATEST"))
.andExpect(jsonPath("$.data.page").value(0))
.andExpect(jsonPath("$.data.size").value(20))
.andExpect(jsonPath("$.data.hasNext").value(false))
.andExpect(jsonPath("$.data.liveReplayContents[0].isOwned").value(true))
.andExpect(jsonPath("$.data.liveReplayContents[0].isRented").value(false))
Mockito.verify(facade).getLiveTab(
eqValue(1L),
eqValue(viewer),
eqValue(ContentSort.LATEST),
eqValue(0),
eqValue(20),
anyValue(LocalDateTime.now())
)
}
@Test
@DisplayName("크리에이터 채널 라이브 탭 조회는 잘못된 page 요청을 기존 오류 응답으로 반환한다")
fun shouldReturnErrorResponseWhenPageIsInvalid() {
val viewer = createMember(id = 10L)
Mockito.doThrow(kr.co.vividnext.sodalive.common.SodaException(messageKey = "common.error.invalid_request"))
.`when`(facade).getLiveTab(
eqValue(1L),
eqValue(viewer),
eqValue(ContentSort.LATEST),
eqValue(-1),
eqValue(20),
anyValue(LocalDateTime.now())
)
mockMvc.perform(
get("/api/v2/creator-channels/1/live")
.param("page", "-1")
.with(user(MemberAdapter(viewer)))
)
.andExpect(status().isOk)
.andExpect(jsonPath("$.success").value(false))
}
@Test
@DisplayName("크리에이터 채널 라이브 탭 조회는 잘못된 size 요청을 기존 오류 응답으로 반환한다")
fun shouldReturnErrorResponseWhenSizeIsInvalid() {
val viewer = createMember(id = 10L)
Mockito.doThrow(kr.co.vividnext.sodalive.common.SodaException(messageKey = "common.error.invalid_request"))
.`when`(facade).getLiveTab(
eqValue(1L),
eqValue(viewer),
eqValue(ContentSort.LATEST),
eqValue(0),
eqValue(0),
anyValue(LocalDateTime.now())
)
mockMvc.perform(
get("/api/v2/creator-channels/1/live")
.param("size", "0")
.with(user(MemberAdapter(viewer)))
)
.andExpect(status().isOk)
.andExpect(jsonPath("$.success").value(false))
}
private fun <T> eqValue(value: T): T {
return Mockito.eq(value) ?: value
}
private fun <T> anyValue(fallback: T): T {
return Mockito.any<T>() ?: fallback
}
private fun createMember(id: Long): Member {
return Member(
email = "viewer$id@test.com",
password = "password",
nickname = "viewer$id",
role = MemberRole.USER
).apply {
this.id = id
}
}
private fun createResponse(): CreatorChannelLiveTabResponse {
return CreatorChannelLiveTabResponse(
liveReplayContentCount = 1,
currentLive = CreatorChannelLiveResponse(
liveId = 101L,
title = "live",
coverImageUrl = "live.png",
beginDateTimeUtc = "2026-06-17T01:00:00Z",
price = 20,
isAdult = true
),
liveReplayContents = listOf(
CreatorChannelAudioContentResponse(
audioContentId = 201L,
title = "audio",
duration = "00:10:00",
imageUrl = "audio.png",
price = 30,
isAdult = false,
isPointAvailable = true,
isFirstContent = true,
seriesName = "series",
isOriginalSeries = true,
isOwned = true,
isRented = false
)
),
sort = ContentSort.LATEST,
page = 0,
size = 20,
hasNext = false
)
}
}