feat(content-preference): 콘텐츠 조회 설정 서버 저장 전환을 반영한다
This commit is contained in:
@@ -4,6 +4,8 @@ import kr.co.vividnext.sodalive.common.ApiResponse
|
||||
import kr.co.vividnext.sodalive.common.SodaException
|
||||
import kr.co.vividnext.sodalive.content.like.PutAudioContentLikeRequest
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import kr.co.vividnext.sodalive.member.contentpreference.MemberContentPreferenceService
|
||||
import kr.co.vividnext.sodalive.member.contentpreference.ViewerContentPreference
|
||||
import org.springframework.data.domain.Pageable
|
||||
import org.springframework.lang.Nullable
|
||||
import org.springframework.security.access.prepost.PreAuthorize
|
||||
@@ -25,7 +27,10 @@ import java.time.temporal.TemporalAdjusters
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/audio-content")
|
||||
class AudioContentController(private val service: AudioContentService) {
|
||||
class AudioContentController(
|
||||
private val service: AudioContentService,
|
||||
private val memberContentPreferenceService: MemberContentPreferenceService
|
||||
) {
|
||||
@PostMapping
|
||||
@PreAuthorize("hasRole('CREATOR')")
|
||||
fun createAudioContent(
|
||||
@@ -112,14 +117,15 @@ class AudioContentController(private val service: AudioContentService) {
|
||||
pageable: Pageable
|
||||
) = run {
|
||||
if (member == null) throw SodaException(messageKey = "common.error.bad_credentials")
|
||||
val preference = resolvePreference(member, isAdultContentVisible, contentType)
|
||||
|
||||
ApiResponse.ok(
|
||||
service.getAudioContentList(
|
||||
creatorId = creatorId,
|
||||
sortType = sortType ?: SortType.NEWEST,
|
||||
categoryId = categoryId ?: 0,
|
||||
isAdultContentVisible = isAdultContentVisible ?: true,
|
||||
contentType = contentType ?: ContentType.ALL,
|
||||
isAdultContentVisible = preference.isAdultContentVisible,
|
||||
contentType = preference.contentType,
|
||||
member = member,
|
||||
offset = pageable.offset,
|
||||
limit = pageable.pageSize.toLong()
|
||||
@@ -135,12 +141,13 @@ class AudioContentController(private val service: AudioContentService) {
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
||||
) = run {
|
||||
if (member == null) throw SodaException(messageKey = "common.error.bad_credentials")
|
||||
val preference = resolvePreference(member, isAdultContentVisible, null)
|
||||
|
||||
ApiResponse.ok(
|
||||
service.getDetail(
|
||||
id = id,
|
||||
member = member,
|
||||
isAdultContentVisible = isAdultContentVisible ?: true,
|
||||
isAdultContentVisible = preference.isAdultContentVisible,
|
||||
timezone = timezone
|
||||
)
|
||||
)
|
||||
@@ -192,6 +199,7 @@ class AudioContentController(private val service: AudioContentService) {
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?,
|
||||
pageable: Pageable
|
||||
) = run {
|
||||
val preference = resolvePreference(member, isAdultContentVisible, contentType)
|
||||
val currentDateTime = LocalDateTime.now()
|
||||
val startDate = currentDateTime
|
||||
.withHour(15)
|
||||
@@ -204,8 +212,8 @@ class AudioContentController(private val service: AudioContentService) {
|
||||
|
||||
ApiResponse.ok(
|
||||
service.getAudioContentRanking(
|
||||
isAdult = member?.auth != null && (isAdultContentVisible ?: true),
|
||||
contentType = contentType ?: ContentType.ALL,
|
||||
isAdult = preference.isAdult,
|
||||
contentType = preference.contentType,
|
||||
startDate = startDate,
|
||||
endDate = endDate,
|
||||
offset = pageable.offset,
|
||||
@@ -249,17 +257,18 @@ class AudioContentController(private val service: AudioContentService) {
|
||||
pageable: Pageable
|
||||
) = run {
|
||||
if (member == null) throw SodaException(messageKey = "common.error.bad_credentials")
|
||||
val preference = resolvePreference(member, isAdultContentVisible, contentType)
|
||||
|
||||
ApiResponse.ok(
|
||||
service.getLatestContentByTheme(
|
||||
memberId = member.id!!,
|
||||
theme = if (theme == null) listOf() else listOf(theme),
|
||||
contentType = contentType ?: ContentType.ALL,
|
||||
contentType = preference.contentType,
|
||||
offset = pageable.offset,
|
||||
limit = pageable.pageSize.toLong(),
|
||||
sortType = sortType ?: SortType.NEWEST,
|
||||
isFree = isFree ?: false,
|
||||
isAdult = (isAdultContentVisible ?: true) && member.auth != null,
|
||||
isAdult = preference.isAdult,
|
||||
isPointAvailableOnly = isPointAvailableOnly ?: false
|
||||
)
|
||||
)
|
||||
@@ -271,18 +280,36 @@ class AudioContentController(private val service: AudioContentService) {
|
||||
@RequestParam("contentType", required = false) contentType: ContentType? = null,
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
||||
) = run {
|
||||
val preference = resolvePreference(member, isAdultContentVisible, contentType)
|
||||
ApiResponse.ok(
|
||||
service.getLatestContentByTheme(
|
||||
memberId = member?.id,
|
||||
theme = listOf("다시듣기"),
|
||||
contentType = contentType ?: ContentType.ALL,
|
||||
contentType = preference.contentType,
|
||||
isFree = false,
|
||||
isAdult = if (member != null) {
|
||||
(isAdultContentVisible ?: true) && member.auth != null
|
||||
} else {
|
||||
false
|
||||
}
|
||||
isAdult = preference.isAdult
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private fun resolvePreference(
|
||||
member: Member?,
|
||||
isAdultContentVisible: Boolean?,
|
||||
contentType: ContentType?
|
||||
): ViewerContentPreference {
|
||||
if (member == null) {
|
||||
return ViewerContentPreference(
|
||||
countryCode = "KR",
|
||||
isAdultContentVisible = isAdultContentVisible ?: false,
|
||||
contentType = contentType ?: ContentType.ALL,
|
||||
isAdult = false
|
||||
)
|
||||
}
|
||||
|
||||
return memberContentPreferenceService.resolveForQuery(
|
||||
member = member,
|
||||
isAdultContentVisible = isAdultContentVisible,
|
||||
contentType = contentType
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user