diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/room/LiveRoomRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/room/LiveRoomRepository.kt index 5964b99..6d2eb3d 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/room/LiveRoomRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/room/LiveRoomRepository.kt @@ -52,6 +52,7 @@ interface LiveRoomQueryRepository { fun getDonationTotal(roomId: Long, isLiveCreator: Boolean): Int? fun getDonationList(roomId: Long, isLiveCreator: Boolean): List fun getRoomActiveAndChannelNameIsNotNull(memberId: Long): List + fun getActiveRoomIdList(memberId: Long): Int } class LiveRoomQueryRepositoryImpl( @@ -283,4 +284,17 @@ class LiveRoomQueryRepositoryImpl( ) .fetch() } + + override fun getActiveRoomIdList(memberId: Long): Int { + return queryFactory + .select(liveRoom.id) + .from(liveRoom) + .where( + liveRoom.isActive.isTrue + .and(liveRoom.channelName.isNull) + .and(liveRoom.member.id.eq(memberId)) + ) + .fetch() + .size + } } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/room/LiveRoomService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/room/LiveRoomService.kt index a3e682b..2de3e07 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/room/LiveRoomService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/room/LiveRoomService.kt @@ -247,6 +247,10 @@ class LiveRoomService( @Transactional fun createLiveRoom(coverImage: MultipartFile?, requestString: String, member: Member): CreateLiveRoomResponse { + if (repository.getActiveRoomIdList(memberId = member.id!!) >= 3) { + throw SodaException("예약 라이브는 최대 3개까지 가능합니다.") + } + val request = objectMapper.readValue(requestString, CreateLiveRoomRequest::class.java) if (request.coverImageUrl == null && coverImage == null) { throw SodaException("커버이미지를 선택해 주세요.")