feat(content-all): 전체 탭 공개 endpoint를 추가한다
This commit is contained in:
@@ -103,6 +103,7 @@ class SecurityConfig(
|
||||
.antMatchers(HttpMethod.POST, "/charge/payverse/webhook").permitAll()
|
||||
.antMatchers(HttpMethod.GET, "/api/v2/home/recommendations").permitAll()
|
||||
.antMatchers(HttpMethod.GET, "/api/v2/audio/recommendations").permitAll()
|
||||
.antMatchers(HttpMethod.GET, "/api/v2/audio/contents").permitAll()
|
||||
.antMatchers(HttpMethod.GET, "/api/v2/audio/rankings").permitAll()
|
||||
.antMatchers(HttpMethod.GET, "/api/v2/home/rankings/creators").permitAll()
|
||||
// 페이지네이션 하위 경로(/lives, /debut-creators 등)는 인증 필수
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package kr.co.vividnext.sodalive.v2.api.content.all.adapter.`in`.web
|
||||
|
||||
import kr.co.vividnext.sodalive.common.ApiResponse
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import kr.co.vividnext.sodalive.v2.api.content.all.application.MainContentAllFacade
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
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/audio/contents")
|
||||
class MainContentAllController(
|
||||
private val facade: MainContentAllFacade
|
||||
) {
|
||||
@GetMapping
|
||||
fun getContents(
|
||||
@RequestParam(required = false) type: String?,
|
||||
@RequestParam(required = false) sort: String?,
|
||||
@RequestParam(required = false) dayOfWeek: String?,
|
||||
@RequestParam(required = false) page: Int?,
|
||||
@RequestParam(required = false) size: Int?,
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
||||
) = run {
|
||||
ApiResponse.ok(
|
||||
facade.getContents(
|
||||
type = type,
|
||||
sort = sort,
|
||||
dayOfWeek = dayOfWeek,
|
||||
page = page,
|
||||
size = size,
|
||||
member = member
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package kr.co.vividnext.sodalive.v2.api.content.all.adapter.`in`.web
|
||||
|
||||
import kr.co.vividnext.sodalive.common.CountryContext
|
||||
import kr.co.vividnext.sodalive.configs.SecurityConfig
|
||||
import kr.co.vividnext.sodalive.i18n.LangContext
|
||||
import kr.co.vividnext.sodalive.i18n.SodaMessageSource
|
||||
import kr.co.vividnext.sodalive.jwt.JwtAccessDeniedHandler
|
||||
import kr.co.vividnext.sodalive.jwt.JwtAuthenticationEntryPoint
|
||||
import kr.co.vividnext.sodalive.jwt.TokenProvider
|
||||
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.content.all.application.MainContentAllFacade
|
||||
import kr.co.vividnext.sodalive.v2.api.content.all.dto.MainContentAllTabResponse
|
||||
import kr.co.vividnext.sodalive.v2.common.domain.ContentSort
|
||||
import kr.co.vividnext.sodalive.v2.content.all.domain.MainContentAllType
|
||||
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.mock.mockito.MockBean
|
||||
import org.springframework.context.annotation.Import
|
||||
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user
|
||||
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
|
||||
|
||||
@WebMvcTest(MainContentAllController::class)
|
||||
@Import(SecurityConfig::class)
|
||||
class MainContentAllControllerTest @Autowired constructor(
|
||||
private val mockMvc: MockMvc
|
||||
) {
|
||||
@MockBean
|
||||
private lateinit var facade: MainContentAllFacade
|
||||
|
||||
@MockBean
|
||||
private lateinit var countryContext: CountryContext
|
||||
|
||||
@MockBean
|
||||
private lateinit var langContext: LangContext
|
||||
|
||||
@MockBean
|
||||
private lateinit var sodaMessageSource: SodaMessageSource
|
||||
|
||||
@MockBean
|
||||
private lateinit var tokenProvider: TokenProvider
|
||||
|
||||
@MockBean
|
||||
private lateinit var accessDeniedHandler: JwtAccessDeniedHandler
|
||||
|
||||
@MockBean
|
||||
private lateinit var authenticationEntryPoint: JwtAuthenticationEntryPoint
|
||||
|
||||
@Test
|
||||
@DisplayName("전체 탭 조회는 비회원에게 200 OK와 기본 응답을 반환한다")
|
||||
fun shouldAllowAnonymousAndUseDefaultType() {
|
||||
Mockito.doReturn(response(MainContentAllType.AUDIO, ContentSort.LATEST)).`when`(facade)
|
||||
.getContents(null, null, null, null, null, null)
|
||||
|
||||
mockMvc.perform(get("/api/v2/audio/contents"))
|
||||
.andExpect(status().isOk)
|
||||
.andExpect(jsonPath("$.success").value(true))
|
||||
.andExpect(jsonPath("$.data.type").value("AUDIO"))
|
||||
.andExpect(jsonPath("$.data.sort").value("LATEST"))
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("전체 탭 조회는 query parameter와 인증 회원을 facade에 전달한다")
|
||||
fun shouldPassQueryParametersAndMemberToFacade() {
|
||||
val member = Member(
|
||||
email = "viewer@test.com",
|
||||
password = "password",
|
||||
nickname = "viewer",
|
||||
role = MemberRole.USER
|
||||
).apply { id = 10L }
|
||||
Mockito.doReturn(response(MainContentAllType.SERIES, ContentSort.POPULAR)).`when`(facade)
|
||||
.getContents("SERIES", "POPULAR", "MON", 1, 30, member)
|
||||
|
||||
mockMvc.perform(
|
||||
get("/api/v2/audio/contents")
|
||||
.param("type", "SERIES")
|
||||
.param("dayOfWeek", "MON")
|
||||
.param("sort", "POPULAR")
|
||||
.param("page", "1")
|
||||
.param("size", "30")
|
||||
.with(user(MemberAdapter(member)))
|
||||
)
|
||||
.andExpect(status().isOk)
|
||||
.andExpect(jsonPath("$.success").value(true))
|
||||
.andExpect(jsonPath("$.data.type").value("SERIES"))
|
||||
.andExpect(jsonPath("$.data.sort").value("POPULAR"))
|
||||
|
||||
Mockito.verify(facade).getContents("SERIES", "POPULAR", "MON", 1, 30, member)
|
||||
}
|
||||
|
||||
private fun response(type: MainContentAllType, sort: ContentSort): MainContentAllTabResponse {
|
||||
return MainContentAllTabResponse(
|
||||
type = type,
|
||||
totalCount = 0,
|
||||
audios = emptyList(),
|
||||
series = emptyList(),
|
||||
sort = sort,
|
||||
dayOfWeek = null,
|
||||
page = 0,
|
||||
size = 20,
|
||||
hasNext = false
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user