관리자 - 라이브 리스트 #186
| @@ -21,7 +21,12 @@ class AdminLiveController(private val service: AdminLiveService) { | ||||
|  | ||||
|     @GetMapping | ||||
|     @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") | ||||
|     @PreAuthorize("hasRole('ADMIN')") | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| package kr.co.vividnext.sodalive.admin.live | ||||
|  | ||||
| import com.querydsl.core.types.dsl.Expressions | ||||
| import com.querydsl.jpa.impl.JPAQueryFactory | ||||
| import kr.co.vividnext.sodalive.live.recommend.QRecommendLiveCreatorBanner.recommendLiveCreatorBanner | ||||
| import kr.co.vividnext.sodalive.live.recommend.RecommendLiveCreatorBanner | ||||
| @@ -12,15 +13,40 @@ import java.time.LocalDateTime | ||||
|  | ||||
| @Repository | ||||
| class AdminLiveRoomQueryRepository(private val queryFactory: JPAQueryFactory) { | ||||
|     fun getLiveRoomList(): List<LiveRoom> { | ||||
|     fun getLiveRoomList(imageHost: String): List<GetLiveResponseItem> { | ||||
|         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) | ||||
|             .where(liveRoom.isActive.isTrue) | ||||
|             .orderBy(liveRoom.channelName.desc(), liveRoom.beginDateTime.asc()) | ||||
|             .fetch() | ||||
|     } | ||||
|  | ||||
|     fun getLiveRoomTotalCount(): Int { | ||||
|         return queryFactory | ||||
|             .select(liveRoom.id) | ||||
|             .from(liveRoom) | ||||
|             .where(liveRoom.isActive.isTrue) | ||||
|             .fetch() | ||||
|             .size | ||||
|     } | ||||
|  | ||||
|     fun getRecommendCreatorTotalCount(): Int { | ||||
|         return queryFactory | ||||
|             .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.room.cancel.LiveRoomCancel | ||||
| 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.utils.generateFileName | ||||
| import org.springframework.beans.factory.annotation.Value | ||||
| @@ -36,6 +37,7 @@ import java.time.format.DateTimeFormatter | ||||
| @Service | ||||
| class AdminLiveService( | ||||
|     private val recommendCreatorBannerRepository: RecommendLiveCreatorBannerRepository, | ||||
|     private val roomInfoRepository: LiveRoomInfoRedisRepository, | ||||
|     private val roomCancelRepository: LiveRoomCancelRepository, | ||||
|     private val repository: AdminLiveRoomQueryRepository, | ||||
|     private val memberRepository: MemberRepository, | ||||
| @@ -53,28 +55,23 @@ class AdminLiveService( | ||||
|     @Value("\${cloud.aws.cloud-front.host}") | ||||
|     private val coverImageHost: String | ||||
| ) { | ||||
|     fun getLiveList(): GetLiveResponse { | ||||
|         return GetLiveResponse( | ||||
|             liveList = repository.getLiveRoomList() | ||||
|                 .asSequence() | ||||
|                 .map { | ||||
|                     GetLiveResponseItem( | ||||
|                         id = it.id!!, | ||||
|                         title = it.title, | ||||
|                         content = it.notice, | ||||
|                         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 | ||||
|                     ) | ||||
|     fun getLiveList(offset: Long, limit: Long): GetLiveResponse { | ||||
|         val totalCount = repository.getLiveRoomTotalCount() | ||||
|         val liveList = repository.getLiveRoomList(imageHost = coverImageHost) | ||||
|             .map { | ||||
|                 if (it.channelName.isNotBlank()) { | ||||
|                     val roomInfo = roomInfoRepository.findByIdOrNull(it.id) | ||||
|                     it.numberOfParticipants = (roomInfo?.listenerCount ?: 0) + | ||||
|                         (roomInfo?.speakerCount ?: 0) + | ||||
|                         (roomInfo?.managerCount ?: 0) | ||||
|                 } | ||||
|                 .toList() | ||||
|  | ||||
|                 it | ||||
|             } | ||||
|  | ||||
|         return GetLiveResponse( | ||||
|             totalCount = totalCount, | ||||
|             liveList = liveList | ||||
|         ) | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -1,15 +1,18 @@ | ||||
| package kr.co.vividnext.sodalive.admin.live | ||||
|  | ||||
| import com.querydsl.core.annotations.QueryProjection | ||||
| import kr.co.vividnext.sodalive.live.room.LiveRoomType | ||||
|  | ||||
| data class GetLiveResponse( | ||||
|     val totalCount: Int, | ||||
|     val liveList: List<GetLiveResponseItem> | ||||
| ) | ||||
|  | ||||
| data class GetLiveResponseItem( | ||||
| data class GetLiveResponseItem @QueryProjection constructor( | ||||
|     val id: Long, | ||||
|     val title: String, | ||||
|     val content: String, | ||||
|     var numberOfParticipants: Int, | ||||
|     val managerNickname: String, | ||||
|     val coverImageUrl: String, | ||||
|     val channelName: String, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user