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") | @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( | ||||||
|  |         @RequestParam(value = "status", required = false) status: ContentReleaseStatus?, | ||||||
|         @RequestParam(value = "search_word") searchWord: String, |         @RequestParam(value = "search_word") searchWord: String, | ||||||
|         pageable: Pageable |         pageable: Pageable | ||||||
|     ) = ApiResponse.ok(service.searchAudioContent(searchWord, pageable)) |     ) = ApiResponse.ok( | ||||||
|  |         service.searchAudioContent( | ||||||
|  |             status = status ?: ContentReleaseStatus.OPEN, | ||||||
|  |             searchWord, | ||||||
|  |             pageable | ||||||
|  |         ) | ||||||
|  |     ) | ||||||
|  |  | ||||||
|     @PutMapping |     @PutMapping | ||||||
|     fun modifyAudioContent( |     fun modifyAudioContent( | ||||||
|         @RequestBody request: UpdateAdminContentRequest |         @RequestBody request: UpdateAdminContentRequest | ||||||
|     ) = ApiResponse.ok(service.updateAudioContent(request)) |     ) = 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.hashtag.QHashTag.hashTag | ||||||
| import kr.co.vividnext.sodalive.content.main.curation.QAudioContentCuration.audioContentCuration | import kr.co.vividnext.sodalive.content.main.curation.QAudioContentCuration.audioContentCuration | ||||||
| import kr.co.vividnext.sodalive.content.theme.QAudioContentTheme.audioContentTheme | 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.data.jpa.repository.JpaRepository | ||||||
| import org.springframework.stereotype.Repository | import org.springframework.stereotype.Repository | ||||||
| import java.time.LocalDateTime | import java.time.LocalDateTime | ||||||
| @@ -18,9 +19,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( | ||||||
|         imageHost: String, |         status: ContentReleaseStatus = ContentReleaseStatus.OPEN, | ||||||
|         offset: Long, |         offset: Long, | ||||||
|         limit: Long, |         limit: Long, | ||||||
|         searchWord: String = "" |         searchWord: String = "" | ||||||
| @@ -30,9 +35,17 @@ interface AdminAudioContentQueryRepository { | |||||||
| } | } | ||||||
|  |  | ||||||
| class AdminAudioContentQueryRepositoryImpl( | class AdminAudioContentQueryRepositoryImpl( | ||||||
|     private val queryFactory: JPAQueryFactory |     private val queryFactory: JPAQueryFactory, | ||||||
|  |  | ||||||
|  |     @Value("\${cloud.aws.cloud-front.host}") | ||||||
|  |     private val imageHost: String | ||||||
| ) : 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 +57,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 +72,13 @@ class AdminAudioContentQueryRepositoryImpl( | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     override fun getAudioContentList( |     override fun getAudioContentList( | ||||||
|         imageHost: String, |         status: ContentReleaseStatus, | ||||||
|         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 +90,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( | ||||||
|   | |||||||
| @@ -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.admin.content.theme.AdminContentThemeRepository | ||||||
| import kr.co.vividnext.sodalive.aws.cloudfront.AudioContentCloudFront | import kr.co.vividnext.sodalive.aws.cloudfront.AudioContentCloudFront | ||||||
| import kr.co.vividnext.sodalive.common.SodaException | import kr.co.vividnext.sodalive.common.SodaException | ||||||
| import org.springframework.beans.factory.annotation.Value |  | ||||||
| import org.springframework.data.domain.Pageable | import org.springframework.data.domain.Pageable | ||||||
| import org.springframework.data.repository.findByIdOrNull | import org.springframework.data.repository.findByIdOrNull | ||||||
| import org.springframework.stereotype.Service | import org.springframework.stereotype.Service | ||||||
| @@ -15,21 +14,17 @@ class AdminContentService( | |||||||
|     private val repository: AdminContentRepository, |     private val repository: AdminContentRepository, | ||||||
|     private val themeRepository: AdminContentThemeRepository, |     private val themeRepository: AdminContentThemeRepository, | ||||||
|     private val audioContentCloudFront: AudioContentCloudFront, |     private val audioContentCloudFront: AudioContentCloudFront, | ||||||
|     private val curationRepository: AdminContentCurationRepository, |     private val curationRepository: AdminContentCurationRepository | ||||||
|  |  | ||||||
|     @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 totalCount = repository.getAudioContentTotalCount(status = status) | ||||||
|         val audioContentAndThemeList = repository.getAudioContentList( |         val audioContentAndThemeList = repository.getAudioContentList( | ||||||
|             imageHost = coverImageHost, |             status = status, | ||||||
|             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,23 +39,25 @@ class AdminContentService( | |||||||
|                 ) |                 ) | ||||||
|                 it |                 it | ||||||
|             } |             } | ||||||
|             .toList() |  | ||||||
|  |  | ||||||
|         return GetAdminContentListResponse(totalCount, audioContentList) |         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글자 이상 입력하세요.") |         if (searchWord.length < 2) throw SodaException("2글자 이상 입력하세요.") | ||||||
|         val totalCount = repository.getAudioContentTotalCount(searchWord) |         val totalCount = repository.getAudioContentTotalCount(searchWord, status = status) | ||||||
|         val audioContentAndThemeList = repository.getAudioContentList( |         val audioContentAndThemeList = repository.getAudioContentList( | ||||||
|             imageHost = coverImageHost, |             status = status, | ||||||
|             offset = pageable.offset, |             offset = pageable.offset, | ||||||
|             limit = pageable.pageSize.toLong(), |             limit = pageable.pageSize.toLong(), | ||||||
|             searchWord = searchWord |             searchWord = searchWord | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|         val audioContentList = audioContentAndThemeList |         val audioContentList = audioContentAndThemeList | ||||||
|             .asSequence() |  | ||||||
|             .map { |             .map { | ||||||
|                 val tags = repository |                 val tags = repository | ||||||
|                     .getHashTagList(audioContentId = it.audioContentId) |                     .getHashTagList(audioContentId = it.audioContentId) | ||||||
| @@ -75,7 +72,6 @@ class AdminContentService( | |||||||
|                 ) |                 ) | ||||||
|                 it |                 it | ||||||
|             } |             } | ||||||
|             .toList() |  | ||||||
|  |  | ||||||
|         return GetAdminContentListResponse(totalCount, audioContentList) |         return GetAdminContentListResponse(totalCount, audioContentList) | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user