Merge pull request '관리자 - 콘텐츠 리스트' (#227) from test into main
Reviewed-on: #227
This commit is contained in:
		| @@ -15,16 +15,39 @@ 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( | ||||
|         @RequestParam(value = "status", required = false) status: ContentReleaseStatus?, | ||||
|         @RequestParam(value = "search_word") searchWord: String, | ||||
|         pageable: Pageable | ||||
|     ) = ApiResponse.ok(service.searchAudioContent(searchWord, pageable)) | ||||
|     ) = ApiResponse.ok( | ||||
|         service.searchAudioContent( | ||||
|             status = status ?: ContentReleaseStatus.OPEN, | ||||
|             searchWord, | ||||
|             pageable | ||||
|         ) | ||||
|     ) | ||||
|  | ||||
|     @PutMapping | ||||
|     fun modifyAudioContent( | ||||
|         @RequestBody request: UpdateAdminContentRequest | ||||
|     ) = ApiResponse.ok(service.updateAudioContent(request)) | ||||
| } | ||||
|  | ||||
| enum class ContentReleaseStatus { | ||||
|     // 콘텐츠가 공개된 상태 | ||||
|     OPEN, | ||||
|  | ||||
|     // 예약된 콘텐츠, 아직 공개되지 않은 상태 | ||||
|     SCHEDULED | ||||
| } | ||||
|   | ||||
| @@ -10,6 +10,7 @@ import kr.co.vividnext.sodalive.content.hashtag.QAudioContentHashTag.audioConten | ||||
| import kr.co.vividnext.sodalive.content.hashtag.QHashTag.hashTag | ||||
| import kr.co.vividnext.sodalive.content.main.curation.QAudioContentCuration.audioContentCuration | ||||
| import kr.co.vividnext.sodalive.content.theme.QAudioContentTheme.audioContentTheme | ||||
| import org.springframework.beans.factory.annotation.Value | ||||
| import org.springframework.data.jpa.repository.JpaRepository | ||||
| import org.springframework.stereotype.Repository | ||||
| import java.time.LocalDateTime | ||||
| @@ -18,9 +19,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( | ||||
|         imageHost: String, | ||||
|         status: ContentReleaseStatus = ContentReleaseStatus.OPEN, | ||||
|         offset: Long, | ||||
|         limit: Long, | ||||
|         searchWord: String = "" | ||||
| @@ -30,9 +35,17 @@ interface AdminAudioContentQueryRepository { | ||||
| } | ||||
|  | ||||
| class AdminAudioContentQueryRepositoryImpl( | ||||
|     private val queryFactory: JPAQueryFactory | ||||
|     private val queryFactory: JPAQueryFactory, | ||||
|  | ||||
|     @Value("\${cloud.aws.cloud-front.host}") | ||||
|     private val imageHost: String | ||||
| ) : 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 +57,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 +72,13 @@ class AdminAudioContentQueryRepositoryImpl( | ||||
|     } | ||||
|  | ||||
|     override fun getAudioContentList( | ||||
|         imageHost: String, | ||||
|         status: ContentReleaseStatus, | ||||
|         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 +90,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( | ||||
|   | ||||
| @@ -4,7 +4,6 @@ import kr.co.vividnext.sodalive.admin.content.curation.AdminContentCurationRepos | ||||
| import kr.co.vividnext.sodalive.admin.content.theme.AdminContentThemeRepository | ||||
| import kr.co.vividnext.sodalive.aws.cloudfront.AudioContentCloudFront | ||||
| import kr.co.vividnext.sodalive.common.SodaException | ||||
| import org.springframework.beans.factory.annotation.Value | ||||
| import org.springframework.data.domain.Pageable | ||||
| import org.springframework.data.repository.findByIdOrNull | ||||
| import org.springframework.stereotype.Service | ||||
| @@ -15,21 +14,17 @@ class AdminContentService( | ||||
|     private val repository: AdminContentRepository, | ||||
|     private val themeRepository: AdminContentThemeRepository, | ||||
|     private val audioContentCloudFront: AudioContentCloudFront, | ||||
|     private val curationRepository: AdminContentCurationRepository, | ||||
|  | ||||
|     @Value("\${cloud.aws.cloud-front.host}") | ||||
|     private val coverImageHost: String | ||||
|     private val curationRepository: AdminContentCurationRepository | ||||
| ) { | ||||
|     fun getAudioContentList(pageable: Pageable): GetAdminContentListResponse { | ||||
|         val totalCount = repository.getAudioContentTotalCount() | ||||
|     fun getAudioContentList(status: ContentReleaseStatus, pageable: Pageable): GetAdminContentListResponse { | ||||
|         val totalCount = repository.getAudioContentTotalCount(status = status) | ||||
|         val audioContentAndThemeList = repository.getAudioContentList( | ||||
|             imageHost = coverImageHost, | ||||
|             status = status, | ||||
|             offset = pageable.offset, | ||||
|             limit = pageable.pageSize.toLong() | ||||
|         ) | ||||
|  | ||||
|         val audioContentList = audioContentAndThemeList | ||||
|             .asSequence() | ||||
|             .map { | ||||
|                 val tags = repository | ||||
|                     .getHashTagList(audioContentId = it.audioContentId) | ||||
| @@ -44,23 +39,25 @@ class AdminContentService( | ||||
|                 ) | ||||
|                 it | ||||
|             } | ||||
|             .toList() | ||||
|  | ||||
|         return GetAdminContentListResponse(totalCount, audioContentList) | ||||
|     } | ||||
|  | ||||
|     fun searchAudioContent(searchWord: String, pageable: Pageable): GetAdminContentListResponse { | ||||
|     fun searchAudioContent( | ||||
|         status: ContentReleaseStatus, | ||||
|         searchWord: String, | ||||
|         pageable: Pageable | ||||
|     ): GetAdminContentListResponse { | ||||
|         if (searchWord.length < 2) throw SodaException("2글자 이상 입력하세요.") | ||||
|         val totalCount = repository.getAudioContentTotalCount(searchWord) | ||||
|         val totalCount = repository.getAudioContentTotalCount(searchWord, status = status) | ||||
|         val audioContentAndThemeList = repository.getAudioContentList( | ||||
|             imageHost = coverImageHost, | ||||
|             status = status, | ||||
|             offset = pageable.offset, | ||||
|             limit = pageable.pageSize.toLong(), | ||||
|             searchWord = searchWord | ||||
|         ) | ||||
|  | ||||
|         val audioContentList = audioContentAndThemeList | ||||
|             .asSequence() | ||||
|             .map { | ||||
|                 val tags = repository | ||||
|                     .getHashTagList(audioContentId = it.audioContentId) | ||||
| @@ -75,7 +72,6 @@ class AdminContentService( | ||||
|                 ) | ||||
|                 it | ||||
|             } | ||||
|             .toList() | ||||
|  | ||||
|         return GetAdminContentListResponse(totalCount, audioContentList) | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user