테마별 콘텐츠 가져오기 API 추가
This commit is contained in:
parent
d621e271a0
commit
144bb4945b
|
@ -3,9 +3,11 @@ package kr.co.vividnext.sodalive.content.theme
|
||||||
import kr.co.vividnext.sodalive.common.ApiResponse
|
import kr.co.vividnext.sodalive.common.ApiResponse
|
||||||
import kr.co.vividnext.sodalive.common.SodaException
|
import kr.co.vividnext.sodalive.common.SodaException
|
||||||
import kr.co.vividnext.sodalive.member.Member
|
import kr.co.vividnext.sodalive.member.Member
|
||||||
|
import org.springframework.data.domain.Pageable
|
||||||
import org.springframework.security.access.prepost.PreAuthorize
|
import org.springframework.security.access.prepost.PreAuthorize
|
||||||
import org.springframework.security.core.annotation.AuthenticationPrincipal
|
import org.springframework.security.core.annotation.AuthenticationPrincipal
|
||||||
import org.springframework.web.bind.annotation.GetMapping
|
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.RequestMapping
|
||||||
import org.springframework.web.bind.annotation.RestController
|
import org.springframework.web.bind.annotation.RestController
|
||||||
|
|
||||||
|
@ -21,4 +23,22 @@ class AudioContentThemeController(private val service: AudioContentThemeService)
|
||||||
|
|
||||||
ApiResponse.ok(service.getThemes())
|
ApiResponse.ok(service.getThemes())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}/content")
|
||||||
|
fun getContentByTheme(
|
||||||
|
@PathVariable id: Long,
|
||||||
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?,
|
||||||
|
pageable: Pageable
|
||||||
|
) = run {
|
||||||
|
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
||||||
|
|
||||||
|
ApiResponse.ok(
|
||||||
|
service.getContentByTheme(
|
||||||
|
themeId = id,
|
||||||
|
member = member,
|
||||||
|
offset = pageable.offset,
|
||||||
|
limit = pageable.pageSize.toLong()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,48 @@
|
||||||
package kr.co.vividnext.sodalive.content.theme
|
package kr.co.vividnext.sodalive.content.theme
|
||||||
|
|
||||||
|
import kr.co.vividnext.sodalive.common.SodaException
|
||||||
|
import kr.co.vividnext.sodalive.content.AudioContentRepository
|
||||||
|
import kr.co.vividnext.sodalive.content.theme.content.GetContentByThemeResponse
|
||||||
|
import kr.co.vividnext.sodalive.member.Member
|
||||||
|
import kr.co.vividnext.sodalive.member.block.BlockMemberRepository
|
||||||
|
import org.springframework.beans.factory.annotation.Value
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
import org.springframework.transaction.annotation.Transactional
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class AudioContentThemeService(private val queryRepository: AudioContentThemeQueryRepository) {
|
class AudioContentThemeService(
|
||||||
|
private val queryRepository: AudioContentThemeQueryRepository,
|
||||||
|
private val blockMemberRepository: BlockMemberRepository,
|
||||||
|
private val contentRepository: AudioContentRepository,
|
||||||
|
|
||||||
|
@Value("\${cloud.aws.cloud-front.host}")
|
||||||
|
private val imageHost: String
|
||||||
|
) {
|
||||||
|
@Transactional(readOnly = true)
|
||||||
fun getThemes(): List<GetAudioContentThemeResponse> {
|
fun getThemes(): List<GetAudioContentThemeResponse> {
|
||||||
return queryRepository.getActiveThemes()
|
return queryRepository.getActiveThemes()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
fun getContentByTheme(themeId: Long, member: Member, offset: Long, limit: Long): GetContentByThemeResponse {
|
||||||
|
val theme = queryRepository.findThemeByIdAndActive(themeId)
|
||||||
|
?: throw SodaException("잘못된 요청입니다.")
|
||||||
|
|
||||||
|
val items = contentRepository.findByTheme(
|
||||||
|
cloudfrontHost = imageHost,
|
||||||
|
memberId = member.id!!,
|
||||||
|
theme = theme.theme,
|
||||||
|
isAdult = member.auth != null,
|
||||||
|
offset = offset,
|
||||||
|
limit = limit
|
||||||
|
)
|
||||||
|
.asSequence()
|
||||||
|
.filter { !blockMemberRepository.isBlocked(blockedMemberId = member.id!!, memberId = it.creatorId) }
|
||||||
|
.toList()
|
||||||
|
|
||||||
|
return GetContentByThemeResponse(
|
||||||
|
theme = theme.theme,
|
||||||
|
items = items
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
package kr.co.vividnext.sodalive.content.theme.content
|
||||||
|
|
||||||
|
import kr.co.vividnext.sodalive.content.main.GetAudioContentMainItem
|
||||||
|
|
||||||
|
data class GetContentByThemeResponse(
|
||||||
|
val theme: String,
|
||||||
|
val items: List<GetAudioContentMainItem>
|
||||||
|
)
|
Loading…
Reference in New Issue