feat(home): 홈 추천 조회 컨트롤러를 추가한다

This commit is contained in:
2026-06-01 13:55:53 +09:00
parent 3df5614b7a
commit fb0f22070f
3 changed files with 299 additions and 2 deletions

View File

@@ -101,6 +101,9 @@ class SecurityConfig(
.antMatchers(HttpMethod.GET, "/api/chat/room/list").permitAll()
.antMatchers(HttpMethod.GET, "/api/chat/original/list").permitAll()
.antMatchers(HttpMethod.POST, "/charge/payverse/webhook").permitAll()
.antMatchers(HttpMethod.GET, "/api/v2/home/recommendations").permitAll()
// 페이지네이션 하위 경로(/lives, /debut-creators 등)는 인증 필수
.antMatchers(HttpMethod.GET, "/api/v2/home/recommendations/**").authenticated()
.anyRequest().authenticated()
.and()
.build()

View File

@@ -3,38 +3,123 @@ package kr.co.vividnext.sodalive.v2.api.home.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.home.application.HomeRecommendationFacade
import kr.co.vividnext.sodalive.v2.api.home.dto.FollowRecommendedCreatorsRequest
import kr.co.vividnext.sodalive.v2.recommend.application.RecommendedCreatorFollowService
import org.springframework.security.core.annotation.AuthenticationPrincipal
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
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/home/recommendations")
class HomeRecommendationController(
private val homeRecommendationFacade: HomeRecommendationFacade,
private val recommendedCreatorFollowService: RecommendedCreatorFollowService
) {
@GetMapping
fun getHomeRecommendations(
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
ApiResponse.ok(homeRecommendationFacade.getHomeRecommendations(member))
}
@GetMapping("/lives")
fun getLives(
@RequestParam(defaultValue = "0") page: Int,
@RequestParam(defaultValue = "$DEFAULT_PAGE_SIZE") size: Int,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
ApiResponse.ok(
homeRecommendationFacade.getLives(
requireMember(member),
normalizePage(page),
normalizeSize(size)
)
)
}
@GetMapping("/debut-creators")
fun getDebutCreators(
@RequestParam(defaultValue = "0") page: Int,
@RequestParam(defaultValue = "$DEFAULT_PAGE_SIZE") size: Int,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
ApiResponse.ok(
homeRecommendationFacade.getRecentDebutCreators(
requireMember(member),
normalizePage(page),
normalizeSize(size)
)
)
}
@GetMapping("/first-audio-contents")
fun getFirstAudioContents(
@RequestParam(defaultValue = "0") page: Int,
@RequestParam(defaultValue = "$DEFAULT_PAGE_SIZE") size: Int,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
ApiResponse.ok(
homeRecommendationFacade.getFirstAudioContents(
requireMember(member),
normalizePage(page),
normalizeSize(size)
)
)
}
@GetMapping("/ai-characters")
fun getAiCharacters(
@RequestParam(defaultValue = "0") page: Int,
@RequestParam(defaultValue = "$DEFAULT_PAGE_SIZE") size: Int,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
ApiResponse.ok(
homeRecommendationFacade.getAiCharacters(
requireMember(member),
normalizePage(page),
normalizeSize(size)
)
)
}
@PostMapping("/creators/follow")
fun followRecommendedCreators(
@RequestBody request: FollowRecommendedCreatorsRequest,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
if (member == null) throw SodaException(messageKey = "common.error.bad_credentials")
val authenticatedMember = requireMember(member)
val creatorIds = request.creatorIds
if (creatorIds.isNullOrEmpty() || creatorIds.size > MAX_CREATOR_IDS) {
throw SodaException(messageKey = "common.error.invalid_request")
}
recommendedCreatorFollowService.followCreators(
member = member,
member = authenticatedMember,
creatorIds = creatorIds
)
ApiResponse.ok<Unit>()
}
private fun requireMember(member: Member?): Member {
return member ?: throw SodaException(messageKey = "common.error.bad_credentials")
}
private fun normalizePage(page: Int): Int = page.coerceIn(0, MAX_PAGE)
private fun normalizeSize(size: Int): Int {
if (size < 1) return DEFAULT_PAGE_SIZE
return minOf(size, MAX_PAGE_SIZE)
}
companion object {
private const val MAX_CREATOR_IDS = 50
private const val DEFAULT_PAGE_SIZE = 20
private const val MAX_PAGE_SIZE = 50
private const val MAX_PAGE = 10_000
}
}