feat(audio-recommendation): 오디오 추천 조회 endpoint를 추가한다
This commit is contained in:
@@ -102,6 +102,7 @@ class SecurityConfig(
|
|||||||
.antMatchers(HttpMethod.GET, "/api/chat/original/list").permitAll()
|
.antMatchers(HttpMethod.GET, "/api/chat/original/list").permitAll()
|
||||||
.antMatchers(HttpMethod.POST, "/charge/payverse/webhook").permitAll()
|
.antMatchers(HttpMethod.POST, "/charge/payverse/webhook").permitAll()
|
||||||
.antMatchers(HttpMethod.GET, "/api/v2/home/recommendations").permitAll()
|
.antMatchers(HttpMethod.GET, "/api/v2/home/recommendations").permitAll()
|
||||||
|
.antMatchers(HttpMethod.GET, "/api/v2/audio/recommendations").permitAll()
|
||||||
.antMatchers(HttpMethod.GET, "/api/v2/home/rankings/creators").permitAll()
|
.antMatchers(HttpMethod.GET, "/api/v2/home/rankings/creators").permitAll()
|
||||||
// 페이지네이션 하위 경로(/lives, /debut-creators 등)는 인증 필수
|
// 페이지네이션 하위 경로(/lives, /debut-creators 등)는 인증 필수
|
||||||
.antMatchers(HttpMethod.GET, "/api/v2/home/recommendations/**").authenticated()
|
.antMatchers(HttpMethod.GET, "/api/v2/home/recommendations/**").authenticated()
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package kr.co.vividnext.sodalive.v2.api.audio.recommendation.adapter.`in`.web
|
||||||
|
|
||||||
|
import kr.co.vividnext.sodalive.common.ApiResponse
|
||||||
|
import kr.co.vividnext.sodalive.member.Member
|
||||||
|
import kr.co.vividnext.sodalive.v2.api.audio.recommendation.application.AudioRecommendationFacade
|
||||||
|
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.RestController
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/v2/audio/recommendations")
|
||||||
|
class AudioRecommendationController(
|
||||||
|
private val audioRecommendationFacade: AudioRecommendationFacade
|
||||||
|
) {
|
||||||
|
@GetMapping
|
||||||
|
fun getRecommendations(
|
||||||
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
||||||
|
) = run {
|
||||||
|
ApiResponse.ok(audioRecommendationFacade.getRecommendations(member))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
package kr.co.vividnext.sodalive.v2.api.audio.recommendation.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.audio.recommendation.application.AudioRecommendationFacade
|
||||||
|
import kr.co.vividnext.sodalive.v2.api.audio.recommendation.dto.AudioRecommendationsResponse
|
||||||
|
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(AudioRecommendationController::class)
|
||||||
|
@Import(SecurityConfig::class)
|
||||||
|
class AudioRecommendationControllerTest @Autowired constructor(
|
||||||
|
private val mockMvc: MockMvc
|
||||||
|
) {
|
||||||
|
@MockBean
|
||||||
|
private lateinit var facade: AudioRecommendationFacade
|
||||||
|
|
||||||
|
@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와 ApiResponse.ok wrapper를 반환한다")
|
||||||
|
fun shouldReturnRecommendationsForAnonymous() {
|
||||||
|
Mockito.doReturn(emptyResponse()).`when`(facade).getRecommendations(null)
|
||||||
|
|
||||||
|
mockMvc.perform(get("/api/v2/audio/recommendations"))
|
||||||
|
.andExpect(status().isOk)
|
||||||
|
.andExpect(jsonPath("$.success").value(true))
|
||||||
|
.andExpect(jsonPath("$.data.banners").isArray)
|
||||||
|
.andExpect(jsonPath("$.data.originalSeries").isArray)
|
||||||
|
.andExpect(jsonPath("$.data.latestAudios").isArray)
|
||||||
|
.andExpect(jsonPath("$.data.recommendedAudios").isArray)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("오디오 추천 조회는 인증 회원을 nullable member로 facade에 전달한다")
|
||||||
|
fun shouldPassAuthenticatedMemberToFacade() {
|
||||||
|
val member = Member(
|
||||||
|
email = "viewer@test.com",
|
||||||
|
password = "password",
|
||||||
|
nickname = "viewer",
|
||||||
|
role = MemberRole.USER
|
||||||
|
).apply { id = 10L }
|
||||||
|
Mockito.doReturn(emptyResponse()).`when`(facade).getRecommendations(eqValue(member))
|
||||||
|
|
||||||
|
mockMvc.perform(get("/api/v2/audio/recommendations").with(user(MemberAdapter(member))))
|
||||||
|
.andExpect(status().isOk)
|
||||||
|
.andExpect(jsonPath("$.success").value(true))
|
||||||
|
|
||||||
|
Mockito.verify(facade).getRecommendations(eqValue(member))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun emptyResponse(): AudioRecommendationsResponse {
|
||||||
|
return AudioRecommendationsResponse(
|
||||||
|
banners = emptyList(),
|
||||||
|
originalSeries = emptyList(),
|
||||||
|
latestAudios = emptyList(),
|
||||||
|
newAndHotAudios = emptyList(),
|
||||||
|
freeAudios = emptyList(),
|
||||||
|
pointAudios = emptyList(),
|
||||||
|
mostCommentedAudios = emptyList(),
|
||||||
|
recommendedAudios = emptyList()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun <T> eqValue(value: T): T {
|
||||||
|
return Mockito.eq(value) ?: value
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user