From 2c4c19990a693ad5b93f4cbe4804a2aa3250d63d Mon Sep 17 00:00:00 2001 From: Klaus Date: Fri, 20 Sep 2024 01:04:02 +0900 Subject: [PATCH] =?UTF-8?q?=EB=9D=BC=EC=9D=B4=EB=B8=8C=20-=20=ED=9B=84?= =?UTF-8?q?=EC=9B=90=ED=98=84=ED=99=A9=20API=20-=20=EB=B0=A9=EC=9E=A5?= =?UTF-8?q?=EC=9D=80=20=EB=B9=84=EB=B0=80=ED=9B=84=EC=9B=90=20=EB=82=B4?= =?UTF-8?q?=EC=97=AD=EB=8F=84=20=EB=B0=98=EC=98=81=EB=90=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sodalive/live/room/LiveRoomController.kt | 4 +- .../sodalive/live/room/LiveRoomRepository.kt | 38 +++++++++++-------- .../sodalive/live/room/LiveRoomService.kt | 12 ++++-- 3 files changed, 32 insertions(+), 22 deletions(-) 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(