Merge pull request '관리자 - 라이브 리스트' (#186) from test into main
Reviewed-on: #186
This commit is contained in:
		| @@ -21,7 +21,12 @@ class AdminLiveController(private val service: AdminLiveService) { | |||||||
|  |  | ||||||
|     @GetMapping |     @GetMapping | ||||||
|     @PreAuthorize("hasRole('ADMIN')") |     @PreAuthorize("hasRole('ADMIN')") | ||||||
|     fun getOnAirLive() = ApiResponse.ok(data = service.getLiveList()) |     fun getLive(pageable: Pageable) = ApiResponse.ok( | ||||||
|  |         data = service.getLiveList( | ||||||
|  |             offset = pageable.offset, | ||||||
|  |             limit = pageable.pageSize.toLong() | ||||||
|  |         ) | ||||||
|  |     ) | ||||||
|  |  | ||||||
|     @GetMapping("/recommend-creator") |     @GetMapping("/recommend-creator") | ||||||
|     @PreAuthorize("hasRole('ADMIN')") |     @PreAuthorize("hasRole('ADMIN')") | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| package kr.co.vividnext.sodalive.admin.live | package kr.co.vividnext.sodalive.admin.live | ||||||
|  |  | ||||||
|  | import com.querydsl.core.types.dsl.Expressions | ||||||
| import com.querydsl.jpa.impl.JPAQueryFactory | import com.querydsl.jpa.impl.JPAQueryFactory | ||||||
| import kr.co.vividnext.sodalive.live.recommend.QRecommendLiveCreatorBanner.recommendLiveCreatorBanner | import kr.co.vividnext.sodalive.live.recommend.QRecommendLiveCreatorBanner.recommendLiveCreatorBanner | ||||||
| import kr.co.vividnext.sodalive.live.recommend.RecommendLiveCreatorBanner | import kr.co.vividnext.sodalive.live.recommend.RecommendLiveCreatorBanner | ||||||
| @@ -12,15 +13,40 @@ import java.time.LocalDateTime | |||||||
|  |  | ||||||
| @Repository | @Repository | ||||||
| class AdminLiveRoomQueryRepository(private val queryFactory: JPAQueryFactory) { | class AdminLiveRoomQueryRepository(private val queryFactory: JPAQueryFactory) { | ||||||
|     fun getLiveRoomList(): List<LiveRoom> { |     fun getLiveRoomList(imageHost: String): List<GetLiveResponseItem> { | ||||||
|         return queryFactory |         return queryFactory | ||||||
|             .selectFrom(liveRoom) |             .select( | ||||||
|  |                 QGetLiveResponseItem( | ||||||
|  |                     liveRoom.id, | ||||||
|  |                     liveRoom.title, | ||||||
|  |                     liveRoom.notice, | ||||||
|  |                     Expressions.constant(0), | ||||||
|  |                     liveRoom.member.nickname, | ||||||
|  |                     liveRoom.coverImage.coalesce("profile/default-profile.png") | ||||||
|  |                         .prepend("/") | ||||||
|  |                         .prepend(imageHost), | ||||||
|  |                     liveRoom.channelName.coalesce(""), | ||||||
|  |                     liveRoom.type, | ||||||
|  |                     liveRoom.password, | ||||||
|  |                     liveRoom.isAdult | ||||||
|  |                 ) | ||||||
|  |             ) | ||||||
|  |             .from(liveRoom) | ||||||
|             .innerJoin(liveRoom.member, member) |             .innerJoin(liveRoom.member, member) | ||||||
|             .where(liveRoom.isActive.isTrue) |             .where(liveRoom.isActive.isTrue) | ||||||
|             .orderBy(liveRoom.channelName.desc(), liveRoom.beginDateTime.asc()) |             .orderBy(liveRoom.channelName.desc(), liveRoom.beginDateTime.asc()) | ||||||
|             .fetch() |             .fetch() | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     fun getLiveRoomTotalCount(): Int { | ||||||
|  |         return queryFactory | ||||||
|  |             .select(liveRoom.id) | ||||||
|  |             .from(liveRoom) | ||||||
|  |             .where(liveRoom.isActive.isTrue) | ||||||
|  |             .fetch() | ||||||
|  |             .size | ||||||
|  |     } | ||||||
|  |  | ||||||
|     fun getRecommendCreatorTotalCount(): Int { |     fun getRecommendCreatorTotalCount(): Int { | ||||||
|         return queryFactory |         return queryFactory | ||||||
|             .select(recommendLiveCreatorBanner.id) |             .select(recommendLiveCreatorBanner.id) | ||||||
|   | |||||||
| @@ -20,6 +20,7 @@ import kr.co.vividnext.sodalive.live.recommend.RecommendLiveCreatorBannerReposit | |||||||
| import kr.co.vividnext.sodalive.live.reservation.LiveReservationRepository | import kr.co.vividnext.sodalive.live.reservation.LiveReservationRepository | ||||||
| import kr.co.vividnext.sodalive.live.room.cancel.LiveRoomCancel | import kr.co.vividnext.sodalive.live.room.cancel.LiveRoomCancel | ||||||
| import kr.co.vividnext.sodalive.live.room.cancel.LiveRoomCancelRepository | import kr.co.vividnext.sodalive.live.room.cancel.LiveRoomCancelRepository | ||||||
|  | import kr.co.vividnext.sodalive.live.room.info.LiveRoomInfoRedisRepository | ||||||
| import kr.co.vividnext.sodalive.member.MemberRepository | import kr.co.vividnext.sodalive.member.MemberRepository | ||||||
| import kr.co.vividnext.sodalive.utils.generateFileName | import kr.co.vividnext.sodalive.utils.generateFileName | ||||||
| import org.springframework.beans.factory.annotation.Value | import org.springframework.beans.factory.annotation.Value | ||||||
| @@ -36,6 +37,7 @@ import java.time.format.DateTimeFormatter | |||||||
| @Service | @Service | ||||||
| class AdminLiveService( | class AdminLiveService( | ||||||
|     private val recommendCreatorBannerRepository: RecommendLiveCreatorBannerRepository, |     private val recommendCreatorBannerRepository: RecommendLiveCreatorBannerRepository, | ||||||
|  |     private val roomInfoRepository: LiveRoomInfoRedisRepository, | ||||||
|     private val roomCancelRepository: LiveRoomCancelRepository, |     private val roomCancelRepository: LiveRoomCancelRepository, | ||||||
|     private val repository: AdminLiveRoomQueryRepository, |     private val repository: AdminLiveRoomQueryRepository, | ||||||
|     private val memberRepository: MemberRepository, |     private val memberRepository: MemberRepository, | ||||||
| @@ -53,28 +55,23 @@ class AdminLiveService( | |||||||
|     @Value("\${cloud.aws.cloud-front.host}") |     @Value("\${cloud.aws.cloud-front.host}") | ||||||
|     private val coverImageHost: String |     private val coverImageHost: String | ||||||
| ) { | ) { | ||||||
|     fun getLiveList(): GetLiveResponse { |     fun getLiveList(offset: Long, limit: Long): GetLiveResponse { | ||||||
|         return GetLiveResponse( |         val totalCount = repository.getLiveRoomTotalCount() | ||||||
|             liveList = repository.getLiveRoomList() |         val liveList = repository.getLiveRoomList(imageHost = coverImageHost) | ||||||
|                 .asSequence() |             .map { | ||||||
|                 .map { |                 if (it.channelName.isNotBlank()) { | ||||||
|                     GetLiveResponseItem( |                     val roomInfo = roomInfoRepository.findByIdOrNull(it.id) | ||||||
|                         id = it.id!!, |                     it.numberOfParticipants = (roomInfo?.listenerCount ?: 0) + | ||||||
|                         title = it.title, |                         (roomInfo?.speakerCount ?: 0) + | ||||||
|                         content = it.notice, |                         (roomInfo?.managerCount ?: 0) | ||||||
|                         managerNickname = it.member!!.nickname, |  | ||||||
|                         coverImageUrl = if (it.coverImage!!.startsWith("https://")) { |  | ||||||
|                             it.coverImage!! |  | ||||||
|                         } else { |  | ||||||
|                             "$coverImageHost/${it.coverImage!!}" |  | ||||||
|                         }, |  | ||||||
|                         channelName = it.channelName ?: "", |  | ||||||
|                         type = it.type, |  | ||||||
|                         password = it.password, |  | ||||||
|                         isAdult = it.isAdult |  | ||||||
|                     ) |  | ||||||
|                 } |                 } | ||||||
|                 .toList() |  | ||||||
|  |                 it | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |         return GetLiveResponse( | ||||||
|  |             totalCount = totalCount, | ||||||
|  |             liveList = liveList | ||||||
|         ) |         ) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,15 +1,18 @@ | |||||||
| package kr.co.vividnext.sodalive.admin.live | package kr.co.vividnext.sodalive.admin.live | ||||||
|  |  | ||||||
|  | import com.querydsl.core.annotations.QueryProjection | ||||||
| import kr.co.vividnext.sodalive.live.room.LiveRoomType | import kr.co.vividnext.sodalive.live.room.LiveRoomType | ||||||
|  |  | ||||||
| data class GetLiveResponse( | data class GetLiveResponse( | ||||||
|  |     val totalCount: Int, | ||||||
|     val liveList: List<GetLiveResponseItem> |     val liveList: List<GetLiveResponseItem> | ||||||
| ) | ) | ||||||
|  |  | ||||||
| data class GetLiveResponseItem( | data class GetLiveResponseItem @QueryProjection constructor( | ||||||
|     val id: Long, |     val id: Long, | ||||||
|     val title: String, |     val title: String, | ||||||
|     val content: String, |     val content: String, | ||||||
|  |     var numberOfParticipants: Int, | ||||||
|     val managerNickname: String, |     val managerNickname: String, | ||||||
|     val coverImageUrl: String, |     val coverImageUrl: String, | ||||||
|     val channelName: String, |     val channelName: String, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user