Compare commits
2 Commits
df3f045209
...
40c0b72450
Author | SHA1 | Date |
---|---|---|
|
40c0b72450 | |
|
e0c9a2cea7 |
|
@ -1,6 +1,7 @@
|
|||
package kr.co.vividnext.sodalive.admin.content.banner
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import kr.co.vividnext.sodalive.admin.content.series.AdminContentSeriesRepository
|
||||
import kr.co.vividnext.sodalive.aws.s3.S3Uploader
|
||||
import kr.co.vividnext.sodalive.common.SodaException
|
||||
import kr.co.vividnext.sodalive.content.main.banner.AudioContentBanner
|
||||
|
@ -19,6 +20,7 @@ class AdminContentBannerService(
|
|||
private val s3Uploader: S3Uploader,
|
||||
private val repository: AdminContentBannerRepository,
|
||||
private val memberRepository: MemberRepository,
|
||||
private val seriesRepository: AdminContentSeriesRepository,
|
||||
private val eventRepository: EventRepository,
|
||||
private val objectMapper: ObjectMapper,
|
||||
|
||||
|
@ -32,6 +34,10 @@ class AdminContentBannerService(
|
|||
throw SodaException("크리에이터를 선택하세요.")
|
||||
}
|
||||
|
||||
if (request.type == AudioContentBannerType.SERIES && request.seriesId == null) {
|
||||
throw SodaException("시리즈를 선택하세요.")
|
||||
}
|
||||
|
||||
if (request.type == AudioContentBannerType.LINK && request.link == null) {
|
||||
throw SodaException("링크 url을 입력하세요.")
|
||||
}
|
||||
|
@ -52,11 +58,18 @@ class AdminContentBannerService(
|
|||
null
|
||||
}
|
||||
|
||||
val series = if (request.seriesId != null && request.seriesId > 0) {
|
||||
seriesRepository.findByIdOrNull(request.seriesId)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
val audioContentBanner = AudioContentBanner(type = request.type)
|
||||
audioContentBanner.link = request.link
|
||||
audioContentBanner.isAdult = request.isAdult
|
||||
audioContentBanner.event = event
|
||||
audioContentBanner.creator = creator
|
||||
audioContentBanner.series = series
|
||||
repository.save(audioContentBanner)
|
||||
|
||||
val fileName = generateFileName()
|
||||
|
@ -96,30 +109,48 @@ class AdminContentBannerService(
|
|||
audioContentBanner.creator = null
|
||||
audioContentBanner.event = null
|
||||
audioContentBanner.link = null
|
||||
audioContentBanner.series = null
|
||||
|
||||
if (request.type == AudioContentBannerType.CREATOR) {
|
||||
if (request.creatorId != null) {
|
||||
val creator = memberRepository.findByIdOrNull(request.creatorId)
|
||||
?: throw SodaException("크리에이터를 선택하세요.")
|
||||
when (request.type) {
|
||||
AudioContentBannerType.EVENT -> {
|
||||
if (request.eventId != null) {
|
||||
val event = eventRepository.findByIdOrNull(request.eventId)
|
||||
?: throw SodaException("이벤트를 선택하세요.")
|
||||
|
||||
audioContentBanner.creator = creator
|
||||
} else {
|
||||
throw SodaException("크리에이터를 선택하세요.")
|
||||
audioContentBanner.event = event
|
||||
} else {
|
||||
throw SodaException("이벤트를 선택하세요.")
|
||||
}
|
||||
}
|
||||
} else if (request.type == AudioContentBannerType.LINK) {
|
||||
if (request.link != null) {
|
||||
audioContentBanner.link = request.link
|
||||
} else {
|
||||
throw SodaException("링크 url을 입력하세요.")
|
||||
}
|
||||
} else if (request.type == AudioContentBannerType.EVENT) {
|
||||
if (request.eventId != null) {
|
||||
val event = eventRepository.findByIdOrNull(request.eventId)
|
||||
?: throw SodaException("이벤트를 선택하세요.")
|
||||
|
||||
audioContentBanner.event = event
|
||||
} else {
|
||||
throw SodaException("이벤트를 선택하세요.")
|
||||
AudioContentBannerType.CREATOR -> {
|
||||
if (request.creatorId != null) {
|
||||
val creator = memberRepository.findByIdOrNull(request.creatorId)
|
||||
?: throw SodaException("크리에이터를 선택하세요.")
|
||||
|
||||
audioContentBanner.creator = creator
|
||||
} else {
|
||||
throw SodaException("크리에이터를 선택하세요.")
|
||||
}
|
||||
}
|
||||
|
||||
AudioContentBannerType.LINK -> {
|
||||
if (request.link != null) {
|
||||
audioContentBanner.link = request.link
|
||||
} else {
|
||||
throw SodaException("링크 url을 입력하세요.")
|
||||
}
|
||||
}
|
||||
|
||||
AudioContentBannerType.SERIES -> {
|
||||
if (request.seriesId != null) {
|
||||
val series = seriesRepository.findByIdOrNull(request.seriesId)
|
||||
?: throw SodaException("시리즈를 선택하세요.")
|
||||
|
||||
audioContentBanner.series = series
|
||||
} else {
|
||||
throw SodaException("시리즈를 선택하세요.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ data class CreateContentBannerRequest(
|
|||
val type: AudioContentBannerType,
|
||||
val eventId: Long?,
|
||||
val creatorId: Long?,
|
||||
val seriesId: Long?,
|
||||
val link: String?,
|
||||
val isAdult: Boolean
|
||||
)
|
||||
|
|
|
@ -7,6 +7,7 @@ data class UpdateContentBannerRequest(
|
|||
val type: AudioContentBannerType?,
|
||||
val eventId: Long?,
|
||||
val creatorId: Long?,
|
||||
val seriesId: Long?,
|
||||
val link: String?,
|
||||
val isAdult: Boolean?,
|
||||
val isActive: Boolean?
|
||||
|
|
|
@ -5,6 +5,7 @@ import org.springframework.data.domain.Pageable
|
|||
import org.springframework.security.access.prepost.PreAuthorize
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RequestParam
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
@RestController
|
||||
|
@ -13,4 +14,9 @@ import org.springframework.web.bind.annotation.RestController
|
|||
class AdminContentSeriesController(private val service: AdminContentSeriesService) {
|
||||
@GetMapping
|
||||
fun getSeriesList(pageable: Pageable) = ApiResponse.ok(service.getSeriesList(pageable))
|
||||
|
||||
@GetMapping("/search")
|
||||
fun searchSeriesList(
|
||||
@RequestParam(value = "search_word") searchWord: String
|
||||
) = ApiResponse.ok(service.searchSeriesList(searchWord))
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ interface AdminContentSeriesQueryRepository {
|
|||
offset: Long,
|
||||
limit: Long
|
||||
): List<GetAdminSeriesListItem>
|
||||
|
||||
fun searchSeriesList(searchWord: String): List<GetAdminSearchSeriesListItem>
|
||||
}
|
||||
|
||||
class AdminContentSeriesQueryRepositoryImpl(
|
||||
|
@ -31,6 +33,7 @@ class AdminContentSeriesQueryRepositoryImpl(
|
|||
override fun getSeriesTotalCount(): Int {
|
||||
val where = series.isActive.isTrue
|
||||
.and(series.member.isNotNull)
|
||||
.and(series.member.isActive.isTrue)
|
||||
|
||||
return queryFactory
|
||||
.select(series.id)
|
||||
|
@ -43,6 +46,7 @@ class AdminContentSeriesQueryRepositoryImpl(
|
|||
override fun getSeriesList(offset: Long, limit: Long): List<GetAdminSeriesListItem> {
|
||||
val where = series.isActive.isTrue
|
||||
.and(series.member.isNotNull)
|
||||
.and(series.member.isActive.isTrue)
|
||||
|
||||
return queryFactory
|
||||
.select(
|
||||
|
@ -73,4 +77,23 @@ class AdminContentSeriesQueryRepositoryImpl(
|
|||
.orderBy(series.member.id.asc(), series.orders.asc())
|
||||
.fetch()
|
||||
}
|
||||
|
||||
override fun searchSeriesList(searchWord: String): List<GetAdminSearchSeriesListItem> {
|
||||
val where = series.isActive.isTrue
|
||||
.and(series.member.isNotNull)
|
||||
.and(series.member.isActive.isTrue)
|
||||
|
||||
return queryFactory
|
||||
.select(
|
||||
QGetAdminSearchSeriesListItem(
|
||||
series.id,
|
||||
series.title
|
||||
)
|
||||
)
|
||||
.from(series)
|
||||
.innerJoin(series.member, member)
|
||||
.where(where)
|
||||
.orderBy(series.id.desc())
|
||||
.fetch()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,4 +14,8 @@ class AdminContentSeriesService(private val repository: AdminContentSeriesReposi
|
|||
|
||||
return GetAdminSeriesListResponse(totalCount, items)
|
||||
}
|
||||
|
||||
fun searchSeriesList(searchWord: String): List<GetAdminSearchSeriesListItem> {
|
||||
return repository.searchSeriesList(searchWord)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,3 +18,8 @@ data class GetAdminSeriesListItem @QueryProjection constructor(
|
|||
val state: String,
|
||||
val isAdult: Boolean
|
||||
)
|
||||
|
||||
data class GetAdminSearchSeriesListItem @QueryProjection constructor(
|
||||
val id: Long,
|
||||
val title: String
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue