관리자 - 콘텐츠 리스트 #227

Merged
klaus merged 4 commits from test into main 2024-10-16 03:33:23 +00:00
3 changed files with 46 additions and 6 deletions
Showing only changes of commit 7f70e508e4 - Show all commits

View File

@ -15,7 +15,15 @@ import org.springframework.web.bind.annotation.RestController
@RequestMapping("/admin/audio-content") @RequestMapping("/admin/audio-content")
class AdminContentController(private val service: AdminContentService) { class AdminContentController(private val service: AdminContentService) {
@GetMapping("/list") @GetMapping("/list")
fun getAudioContentList(pageable: Pageable) = ApiResponse.ok(service.getAudioContentList(pageable)) fun getAudioContentList(
@RequestParam(value = "status", required = false) status: ContentReleaseStatus?,
pageable: Pageable
) = ApiResponse.ok(
service.getAudioContentList(
status = status ?: ContentReleaseStatus.OPEN,
pageable
)
)
@GetMapping("/search") @GetMapping("/search")
fun searchAudioContent( fun searchAudioContent(
@ -28,3 +36,11 @@ class AdminContentController(private val service: AdminContentService) {
@RequestBody request: UpdateAdminContentRequest @RequestBody request: UpdateAdminContentRequest
) = ApiResponse.ok(service.updateAudioContent(request)) ) = ApiResponse.ok(service.updateAudioContent(request))
} }
enum class ContentReleaseStatus {
// 콘텐츠가 공개된 상태
OPEN,
// 예약된 콘텐츠, 아직 공개되지 않은 상태
SCHEDULED
}

View File

@ -18,8 +18,13 @@ import java.time.LocalDateTime
interface AdminContentRepository : JpaRepository<AudioContent, Long>, AdminAudioContentQueryRepository interface AdminContentRepository : JpaRepository<AudioContent, Long>, AdminAudioContentQueryRepository
interface AdminAudioContentQueryRepository { interface AdminAudioContentQueryRepository {
fun getAudioContentTotalCount(searchWord: String = ""): Int fun getAudioContentTotalCount(
searchWord: String = "",
status: ContentReleaseStatus = ContentReleaseStatus.OPEN
): Int
fun getAudioContentList( fun getAudioContentList(
status: ContentReleaseStatus = ContentReleaseStatus.OPEN,
imageHost: String, imageHost: String,
offset: Long, offset: Long,
limit: Long, limit: Long,
@ -32,7 +37,12 @@ interface AdminAudioContentQueryRepository {
class AdminAudioContentQueryRepositoryImpl( class AdminAudioContentQueryRepositoryImpl(
private val queryFactory: JPAQueryFactory private val queryFactory: JPAQueryFactory
) : AdminAudioContentQueryRepository { ) : AdminAudioContentQueryRepository {
override fun getAudioContentTotalCount(searchWord: String): Int { override fun getAudioContentTotalCount(
searchWord: String,
status: ContentReleaseStatus
): Int {
val now = LocalDateTime.now()
var where = audioContent.duration.isNotNull var where = audioContent.duration.isNotNull
.and(audioContent.member.isNotNull) .and(audioContent.member.isNotNull)
.and(audioContent.isActive.isTrue.or(audioContent.releaseDate.isNotNull)) .and(audioContent.isActive.isTrue.or(audioContent.releaseDate.isNotNull))
@ -44,6 +54,12 @@ class AdminAudioContentQueryRepositoryImpl(
) )
} }
where = if (status == ContentReleaseStatus.SCHEDULED) {
where.and(audioContent.releaseDate.after(now))
} else {
where.and(audioContent.releaseDate.before(now))
}
return queryFactory return queryFactory
.select(audioContent.id) .select(audioContent.id)
.from(audioContent) .from(audioContent)
@ -53,11 +69,14 @@ class AdminAudioContentQueryRepositoryImpl(
} }
override fun getAudioContentList( override fun getAudioContentList(
status: ContentReleaseStatus,
imageHost: String, imageHost: String,
offset: Long, offset: Long,
limit: Long, limit: Long,
searchWord: String searchWord: String
): List<GetAdminContentListItem> { ): List<GetAdminContentListItem> {
val now = LocalDateTime.now()
var where = audioContent.duration.isNotNull var where = audioContent.duration.isNotNull
.and(audioContent.member.isNotNull) .and(audioContent.member.isNotNull)
.and(audioContent.isActive.isTrue.or(audioContent.releaseDate.isNotNull)) .and(audioContent.isActive.isTrue.or(audioContent.releaseDate.isNotNull))
@ -69,6 +88,12 @@ class AdminAudioContentQueryRepositoryImpl(
) )
} }
where = if (status == ContentReleaseStatus.SCHEDULED) {
where.and(audioContent.releaseDate.after(now))
} else {
where.and(audioContent.releaseDate.before(now))
}
return queryFactory return queryFactory
.select( .select(
QGetAdminContentListItem( QGetAdminContentListItem(

View File

@ -20,16 +20,16 @@ class AdminContentService(
@Value("\${cloud.aws.cloud-front.host}") @Value("\${cloud.aws.cloud-front.host}")
private val coverImageHost: String private val coverImageHost: String
) { ) {
fun getAudioContentList(pageable: Pageable): GetAdminContentListResponse { fun getAudioContentList(status: ContentReleaseStatus, pageable: Pageable): GetAdminContentListResponse {
val totalCount = repository.getAudioContentTotalCount() val totalCount = repository.getAudioContentTotalCount()
val audioContentAndThemeList = repository.getAudioContentList( val audioContentAndThemeList = repository.getAudioContentList(
status = status,
imageHost = coverImageHost, imageHost = coverImageHost,
offset = pageable.offset, offset = pageable.offset,
limit = pageable.pageSize.toLong() limit = pageable.pageSize.toLong()
) )
val audioContentList = audioContentAndThemeList val audioContentList = audioContentAndThemeList
.asSequence()
.map { .map {
val tags = repository val tags = repository
.getHashTagList(audioContentId = it.audioContentId) .getHashTagList(audioContentId = it.audioContentId)
@ -44,7 +44,6 @@ class AdminContentService(
) )
it it
} }
.toList()
return GetAdminContentListResponse(totalCount, audioContentList) return GetAdminContentListResponse(totalCount, audioContentList)
} }