diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/room/LiveRoomController.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/room/LiveRoomController.kt index e37f38f..43ab9f6 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/room/LiveRoomController.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/room/LiveRoomController.kt @@ -162,7 +162,7 @@ class LiveRoomController( ) = run { if (member == null) throw SodaException("로그인 정보를 확인해주세요.") - ApiResponse.ok(service.getDonationTotal(roomId)) + ApiResponse.ok(service.getDonationTotal(roomId, memberId = member.id!!)) } @PutMapping("/info/set/speaker") @@ -232,7 +232,7 @@ class LiveRoomController( ) = run { if (member == null) throw SodaException("로그인 정보를 확인해주세요.") - ApiResponse.ok(service.getDonationStatus(roomId)) + ApiResponse.ok(service.getDonationStatus(roomId, memberId = member.id!!)) } @PostMapping("/quit") 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 7526bf7..2667915 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 @@ -49,8 +49,8 @@ interface LiveRoomQueryRepository { fun getLiveRoom(id: Long): LiveRoom? fun getLiveRoomAndAccountId(roomId: Long, memberId: Long): LiveRoom? fun getRecentRoomInfo(memberId: Long): GetRecentRoomInfoResponse? - fun getDonationTotal(roomId: Long): Int? - fun getDonationList(roomId: Long): List + fun getDonationTotal(roomId: Long, isLiveCreator: Boolean): Int? + fun getDonationList(roomId: Long, isLiveCreator: Boolean): List fun getRoomActiveAndChannelNameIsNotNull(memberId: Long): List } @@ -225,22 +225,33 @@ class LiveRoomQueryRepositoryImpl( .fetchFirst() } - override fun getDonationTotal(roomId: Long): Int? { + override fun getDonationTotal(roomId: Long, isLiveCreator: Boolean): Int? { + var where = liveRoom.id.eq(roomId) + .and(useCan.canUsage.eq(CanUsage.DONATION).or(useCan.canUsage.eq(CanUsage.SPIN_ROULETTE))) + .and(useCan.isRefund.isFalse) + + if (!isLiveCreator) { + where = where.and(useCan.isSecret.isFalse) + } + return queryFactory .select(useCanCalculate.can.sum()) .from(useCanCalculate) .innerJoin(useCanCalculate.useCan, useCan) .innerJoin(useCan.room, liveRoom) - .where( - liveRoom.id.eq(roomId) - .and(useCan.canUsage.eq(CanUsage.DONATION).or(useCan.canUsage.eq(CanUsage.SPIN_ROULETTE))) - .and(useCan.isRefund.isFalse) - .and(useCan.isSecret.isFalse) - ) + .where(where) .fetchOne() } - override fun getDonationList(roomId: Long): List { + override fun getDonationList(roomId: Long, isLiveCreator: Boolean): List { + var where = liveRoom.id.eq(roomId) + .and(useCan.canUsage.eq(CanUsage.DONATION).or(useCan.canUsage.eq(CanUsage.SPIN_ROULETTE))) + .and(useCan.isRefund.isFalse) + + if (!isLiveCreator) { + where = where.and(useCan.isSecret.isFalse) + } + return queryFactory .select( QGetLiveRoomDonationItem( @@ -256,12 +267,7 @@ class LiveRoomQueryRepositoryImpl( .from(useCan) .join(useCan.member, member) .groupBy(useCan.member) - .where( - useCan.room.id.eq(roomId) - .and(useCan.canUsage.eq(CanUsage.DONATION).or(useCan.canUsage.eq(CanUsage.SPIN_ROULETTE))) - .and(useCan.isRefund.isFalse) - .and(useCan.isSecret.isFalse) - ) + .where(where) .orderBy(useCan.can.sum().add(useCan.rewardCan.sum()).desc()) .fetch() } 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 0e1621b..7b83ab8 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 @@ -965,9 +965,12 @@ class LiveRoomService( ) } - fun getDonationTotal(roomId: Long): GetLiveRoomDonationTotalResponse { + fun getDonationTotal(roomId: Long, memberId: Long): GetLiveRoomDonationTotalResponse { + val room = repository.getLiveRoom(roomId) + ?: return GetLiveRoomDonationTotalResponse(0) + val isLiveCreator = room.member!!.id == memberId return GetLiveRoomDonationTotalResponse( - totalDonationCan = repository.getDonationTotal(roomId = roomId) ?: 0 + totalDonationCan = repository.getDonationTotal(roomId = roomId, isLiveCreator = isLiveCreator) ?: 0 ) } @@ -1166,9 +1169,10 @@ class LiveRoomService( } } - fun getDonationStatus(roomId: Long): GetLiveRoomDonationStatusResponse { + fun getDonationStatus(roomId: Long, memberId: Long): GetLiveRoomDonationStatusResponse { val room = repository.getLiveRoom(roomId) ?: throw SodaException("잘못된 요청입니다.") - val donationList = repository.getDonationList(roomId = room.id!!) + val isLiveCreator = room.member!!.id == memberId + val donationList = repository.getDonationList(roomId = room.id!!, isLiveCreator = isLiveCreator) val totalCan = donationList.sumOf { it.can } return GetLiveRoomDonationStatusResponse(