콘텐츠 API 추가
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package kr.co.vividnext.sodalive.content.theme
|
||||
|
||||
import kr.co.vividnext.sodalive.common.BaseEntity
|
||||
import javax.persistence.Column
|
||||
import javax.persistence.Entity
|
||||
import javax.persistence.Table
|
||||
|
||||
@Entity
|
||||
@Table(name = "content_theme")
|
||||
data class AudioContentTheme(
|
||||
@Column(nullable = false)
|
||||
var theme: String,
|
||||
@Column(nullable = false)
|
||||
var image: String,
|
||||
@Column(nullable = false)
|
||||
var isActive: Boolean = true,
|
||||
@Column(nullable = false)
|
||||
var orders: Int = 1
|
||||
) : BaseEntity()
|
@@ -0,0 +1,24 @@
|
||||
package kr.co.vividnext.sodalive.content.theme
|
||||
|
||||
import kr.co.vividnext.sodalive.common.ApiResponse
|
||||
import kr.co.vividnext.sodalive.common.SodaException
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import org.springframework.security.access.prepost.PreAuthorize
|
||||
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("/audio-content/theme")
|
||||
@PreAuthorize("hasRole('CREATOR')")
|
||||
class AudioContentThemeController(private val service: AudioContentThemeService) {
|
||||
@GetMapping
|
||||
fun getThemes(
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
||||
) = run {
|
||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
||||
|
||||
ApiResponse.ok(service.getThemes())
|
||||
}
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
package kr.co.vividnext.sodalive.content.theme
|
||||
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory
|
||||
import kr.co.vividnext.sodalive.content.QAudioContent.audioContent
|
||||
import kr.co.vividnext.sodalive.content.theme.QAudioContentTheme.audioContentTheme
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
class AudioContentThemeQueryRepository(
|
||||
private val queryFactory: JPAQueryFactory,
|
||||
@Value("\${cloud.aws.cloud-front.host}")
|
||||
private val cloudFrontHost: String
|
||||
) {
|
||||
fun getActiveThemes(): List<GetAudioContentThemeResponse> {
|
||||
return queryFactory
|
||||
.select(
|
||||
QGetAudioContentThemeResponse(
|
||||
audioContentTheme.id,
|
||||
audioContentTheme.theme,
|
||||
audioContentTheme.image.prepend("/").prepend(cloudFrontHost)
|
||||
)
|
||||
)
|
||||
.from(audioContentTheme)
|
||||
.where(audioContentTheme.isActive.isTrue)
|
||||
.orderBy(audioContentTheme.orders.asc())
|
||||
.fetch()
|
||||
}
|
||||
|
||||
fun getActiveThemeOfContent(isAdult: Boolean = false): List<String> {
|
||||
var where = audioContent.isActive.isTrue
|
||||
.and(audioContentTheme.isActive.isTrue)
|
||||
|
||||
if (!isAdult) {
|
||||
where = where.and(audioContent.isAdult.isFalse)
|
||||
}
|
||||
|
||||
return queryFactory
|
||||
.select(audioContentTheme.theme)
|
||||
.from(audioContent)
|
||||
.innerJoin(audioContent.theme, audioContentTheme)
|
||||
.where(where)
|
||||
.groupBy(audioContentTheme.id)
|
||||
.orderBy(audioContentTheme.orders.asc())
|
||||
.fetch()
|
||||
}
|
||||
|
||||
fun findThemeByIdAndActive(id: Long): AudioContentTheme? {
|
||||
return queryFactory
|
||||
.selectFrom(audioContentTheme)
|
||||
.where(
|
||||
audioContentTheme.id.eq(id)
|
||||
.and(audioContentTheme.isActive.isTrue)
|
||||
)
|
||||
.fetchFirst()
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
package kr.co.vividnext.sodalive.content.theme
|
||||
|
||||
import org.springframework.stereotype.Service
|
||||
|
||||
@Service
|
||||
class AudioContentThemeService(private val queryRepository: AudioContentThemeQueryRepository) {
|
||||
fun getThemes(): List<GetAudioContentThemeResponse> {
|
||||
return queryRepository.getActiveThemes()
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
package kr.co.vividnext.sodalive.content.theme
|
||||
|
||||
import com.querydsl.core.annotations.QueryProjection
|
||||
|
||||
data class GetAudioContentThemeResponse @QueryProjection constructor(
|
||||
val id: Long,
|
||||
val theme: String,
|
||||
val image: String
|
||||
)
|
Reference in New Issue
Block a user