관리자 - 콘텐츠 리스트 #227
| @@ -15,7 +15,15 @@ import org.springframework.web.bind.annotation.RestController | ||||
| @RequestMapping("/admin/audio-content") | ||||
| class AdminContentController(private val service: AdminContentService) { | ||||
|     @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") | ||||
|     fun searchAudioContent( | ||||
| @@ -28,3 +36,11 @@ class AdminContentController(private val service: AdminContentService) { | ||||
|         @RequestBody request: UpdateAdminContentRequest | ||||
|     ) = ApiResponse.ok(service.updateAudioContent(request)) | ||||
| } | ||||
|  | ||||
| enum class ContentReleaseStatus { | ||||
|     // 콘텐츠가 공개된 상태 | ||||
|     OPEN, | ||||
|  | ||||
|     // 예약된 콘텐츠, 아직 공개되지 않은 상태 | ||||
|     SCHEDULED | ||||
| } | ||||
|   | ||||
| @@ -18,8 +18,13 @@ import java.time.LocalDateTime | ||||
| interface AdminContentRepository : JpaRepository<AudioContent, Long>, AdminAudioContentQueryRepository | ||||
|  | ||||
| interface AdminAudioContentQueryRepository { | ||||
|     fun getAudioContentTotalCount(searchWord: String = ""): Int | ||||
|     fun getAudioContentTotalCount( | ||||
|         searchWord: String = "", | ||||
|         status: ContentReleaseStatus = ContentReleaseStatus.OPEN | ||||
|     ): Int | ||||
|  | ||||
|     fun getAudioContentList( | ||||
|         status: ContentReleaseStatus = ContentReleaseStatus.OPEN, | ||||
|         imageHost: String, | ||||
|         offset: Long, | ||||
|         limit: Long, | ||||
| @@ -32,7 +37,12 @@ interface AdminAudioContentQueryRepository { | ||||
| class AdminAudioContentQueryRepositoryImpl( | ||||
|     private val queryFactory: JPAQueryFactory | ||||
| ) : AdminAudioContentQueryRepository { | ||||
|     override fun getAudioContentTotalCount(searchWord: String): Int { | ||||
|     override fun getAudioContentTotalCount( | ||||
|         searchWord: String, | ||||
|         status: ContentReleaseStatus | ||||
|     ): Int { | ||||
|         val now = LocalDateTime.now() | ||||
|  | ||||
|         var where = audioContent.duration.isNotNull | ||||
|             .and(audioContent.member.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 | ||||
|             .select(audioContent.id) | ||||
|             .from(audioContent) | ||||
| @@ -53,11 +69,14 @@ class AdminAudioContentQueryRepositoryImpl( | ||||
|     } | ||||
|  | ||||
|     override fun getAudioContentList( | ||||
|         status: ContentReleaseStatus, | ||||
|         imageHost: String, | ||||
|         offset: Long, | ||||
|         limit: Long, | ||||
|         searchWord: String | ||||
|     ): List<GetAdminContentListItem> { | ||||
|         val now = LocalDateTime.now() | ||||
|  | ||||
|         var where = audioContent.duration.isNotNull | ||||
|             .and(audioContent.member.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 | ||||
|             .select( | ||||
|                 QGetAdminContentListItem( | ||||
|   | ||||
| @@ -20,16 +20,16 @@ class AdminContentService( | ||||
|     @Value("\${cloud.aws.cloud-front.host}") | ||||
|     private val coverImageHost: String | ||||
| ) { | ||||
|     fun getAudioContentList(pageable: Pageable): GetAdminContentListResponse { | ||||
|     fun getAudioContentList(status: ContentReleaseStatus, pageable: Pageable): GetAdminContentListResponse { | ||||
|         val totalCount = repository.getAudioContentTotalCount() | ||||
|         val audioContentAndThemeList = repository.getAudioContentList( | ||||
|             status = status, | ||||
|             imageHost = coverImageHost, | ||||
|             offset = pageable.offset, | ||||
|             limit = pageable.pageSize.toLong() | ||||
|         ) | ||||
|  | ||||
|         val audioContentList = audioContentAndThemeList | ||||
|             .asSequence() | ||||
|             .map { | ||||
|                 val tags = repository | ||||
|                     .getHashTagList(audioContentId = it.audioContentId) | ||||
| @@ -44,7 +44,6 @@ class AdminContentService( | ||||
|                 ) | ||||
|                 it | ||||
|             } | ||||
|             .toList() | ||||
|  | ||||
|         return GetAdminContentListResponse(totalCount, audioContentList) | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user