From 4c9277f61a833caf36af8f67a35928b21db38081 Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 28 Oct 2024 15:25:50 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=EB=9D=BC=EC=9D=B4=EB=B8=8C=20=EB=B0=A9=20?= =?UTF-8?q?=ED=9B=84=EC=9B=90=EB=A6=AC=EC=8A=A4=ED=8A=B8=20-=20=ED=9B=84?= =?UTF-8?q?=EC=9B=90=EB=A6=AC=EC=8A=A4=ED=8A=B8=EC=97=90=20=EC=9D=BC?= =?UTF-8?q?=EB=B0=98=ED=9B=84=EC=9B=90=EA=B3=BC=20=EB=B9=84=EB=B0=80?= =?UTF-8?q?=ED=9B=84=EC=9B=90=20=EA=B0=92=EC=9D=84=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sodalive/live/room/LiveRoomRepository.kt | 40 ++++++++++++------- .../sodalive/live/room/LiveRoomService.kt | 7 +--- .../GetLiveRoomDonationStatusResponse.kt | 3 +- 3 files changed, 30 insertions(+), 20 deletions(-) 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 7348403..c87176b 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 @@ -2,6 +2,7 @@ package kr.co.vividnext.sodalive.live.room import com.querydsl.core.types.Projections import com.querydsl.core.types.dsl.CaseBuilder +import com.querydsl.core.types.dsl.Expressions import com.querydsl.jpa.impl.JPAQueryFactory import kr.co.vividnext.sodalive.can.use.CanUsage import kr.co.vividnext.sodalive.can.use.QUseCan.useCan @@ -49,7 +50,7 @@ interface LiveRoomQueryRepository { fun getLiveRoom(id: Long): LiveRoom? fun getLiveRoomAndAccountId(roomId: Long, memberId: Long): LiveRoom? fun getRecentRoomInfo(memberId: Long): GetRecentRoomInfoResponse? - fun getDonationTotal(roomId: Long, isLiveCreator: Boolean): Int? + fun getDonationTotal(roomId: Long): Int? fun getDonationList(roomId: Long, isLiveCreator: Boolean): List fun getRoomActiveAndChannelNameIsNotNull(memberId: Long): List fun getActiveRoomIdList(memberId: Long): Int @@ -227,14 +228,11 @@ class LiveRoomQueryRepositoryImpl( .fetchFirst() } - override fun getDonationTotal(roomId: Long, isLiveCreator: Boolean): Int? { - var where = liveRoom.id.eq(roomId) + override fun getDonationTotal(roomId: Long): Int? { + val 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) - } + .and(useCan.isSecret.isFalse) return queryFactory .select(useCanCalculate.can.sum()) @@ -246,14 +244,10 @@ class LiveRoomQueryRepositoryImpl( } override fun getDonationList(roomId: Long, isLiveCreator: Boolean): List { - var where = liveRoom.id.eq(roomId) + val 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( @@ -263,13 +257,31 @@ class LiveRoomQueryRepositoryImpl( .prepend(cloudFrontHost), member.nickname, member.id.coalesce(0), - useCan.can.sum().add(useCan.rewardCan.sum()) + Expressions.asNumber( + CaseBuilder() + .`when`(useCan.isSecret.isFalse) + .then(useCan.can.add(useCan.rewardCan)) + .otherwise(0) + ).sum(), + Expressions.asNumber( + CaseBuilder() + .`when`(Expressions.asBoolean(isLiveCreator).isTrue) + .then( + Expressions.asNumber( + CaseBuilder() + .`when`(useCan.isSecret.isTrue) + .then(useCan.can.add(useCan.rewardCan)) + .otherwise(0) + ).sum() + ) + .otherwise(0) + ) ) ) .from(useCan) .innerJoin(useCan.room, liveRoom) .join(useCan.member, member) - .groupBy(useCan.member) + .groupBy(useCan.member.id) .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 8d4fcf0..7f02bc2 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 @@ -973,11 +973,8 @@ class LiveRoomService( } 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, isLiveCreator = isLiveCreator) ?: 0 + totalDonationCan = repository.getDonationTotal(roomId = roomId) ?: 0 ) } @@ -1180,7 +1177,7 @@ class LiveRoomService( val room = repository.getLiveRoom(roomId) ?: throw SodaException("잘못된 요청입니다.") val isLiveCreator = room.member!!.id == memberId val donationList = repository.getDonationList(roomId = room.id!!, isLiveCreator = isLiveCreator) - val totalCan = donationList.sumOf { it.can } + val totalCan = donationList.sumOf { it.can + it.secretCan } return GetLiveRoomDonationStatusResponse( donationList = donationList, diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/room/donation/GetLiveRoomDonationStatusResponse.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/room/donation/GetLiveRoomDonationStatusResponse.kt index 2cc8a12..a251b5d 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/room/donation/GetLiveRoomDonationStatusResponse.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/room/donation/GetLiveRoomDonationStatusResponse.kt @@ -12,5 +12,6 @@ data class GetLiveRoomDonationItem @QueryProjection constructor( val profileImage: String, val nickname: String, val userId: Long, - val can: Int + val can: Int, + val secretCan: Int ) -- 2.40.1 From 9425889e93b65d7b3f7ea21ac13b3cd01fd92e54 Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 28 Oct 2024 16:32:08 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=EB=9D=BC=EC=9D=B4=EB=B8=8C=20=EB=B0=A9=20?= =?UTF-8?q?=ED=9B=84=EC=9B=90=EB=A6=AC=EC=8A=A4=ED=8A=B8=20-=20=ED=9B=84?= =?UTF-8?q?=EC=9B=90=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=ED=95=A9=EA=B3=84=20?= =?UTF-8?q?=EC=9D=BC=EB=B0=98=ED=9B=84=EC=9B=90=EA=B3=BC=20=EB=B9=84?= =?UTF-8?q?=EB=B0=80=ED=9B=84=EC=9B=90=20=EA=B0=92=EC=9D=84=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kr/co/vividnext/sodalive/live/room/LiveRoomService.kt | 6 ++++-- .../live/room/donation/GetLiveRoomDonationStatusResponse.kt | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) 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 7f02bc2..bfeaf41 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 @@ -1177,12 +1177,14 @@ class LiveRoomService( val room = repository.getLiveRoom(roomId) ?: throw SodaException("잘못된 요청입니다.") val isLiveCreator = room.member!!.id == memberId val donationList = repository.getDonationList(roomId = room.id!!, isLiveCreator = isLiveCreator) - val totalCan = donationList.sumOf { it.can + it.secretCan } + val totalCan = donationList.sumOf { it.can } + val totalSecretCan = donationList.sumOf { it.secretCan } return GetLiveRoomDonationStatusResponse( donationList = donationList, totalCount = donationList.size, - totalCan = totalCan + totalCan = totalCan, + totalSecretCan = totalSecretCan ) } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/room/donation/GetLiveRoomDonationStatusResponse.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/room/donation/GetLiveRoomDonationStatusResponse.kt index a251b5d..cb25eb0 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/room/donation/GetLiveRoomDonationStatusResponse.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/room/donation/GetLiveRoomDonationStatusResponse.kt @@ -5,7 +5,8 @@ import com.querydsl.core.annotations.QueryProjection data class GetLiveRoomDonationStatusResponse( val donationList: List, val totalCount: Int, - val totalCan: Int + val totalCan: Int, + val totalSecretCan: Int ) data class GetLiveRoomDonationItem @QueryProjection constructor( -- 2.40.1 From 9fcd1725813c06ef6ccc0a8ff427e8d4e7de269c Mon Sep 17 00:00:00 2001 From: Klaus Date: Tue, 29 Oct 2024 00:28:03 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=EB=9D=BC=EC=9D=B4=EB=B8=8C=20=EB=B0=A9=20?= =?UTF-8?q?=ED=9B=84=EC=9B=90=EB=A6=AC=EC=8A=A4=ED=8A=B8=20-=20=EB=B9=84?= =?UTF-8?q?=EB=B0=80=ED=9B=84=EC=9B=90=20=EC=BA=94=200=EB=B3=B4=EB=8B=A4?= =?UTF-8?q?=20=ED=81=AC=EA=B1=B0=EB=82=98=20=EC=9D=BC=EB=B0=98=ED=9B=84?= =?UTF-8?q?=EC=9B=90=20=EC=BA=94=EC=9D=B4=200=EB=B3=B4=EB=8B=A4=20?= =?UTF-8?q?=ED=81=B0=20=EA=B2=BD=EC=9A=B0=EC=97=90=EB=A7=8C=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/kr/co/vividnext/sodalive/live/room/LiveRoomService.kt | 1 + 1 file changed, 1 insertion(+) 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 bfeaf41..a5211fd 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 @@ -1177,6 +1177,7 @@ class LiveRoomService( val room = repository.getLiveRoom(roomId) ?: throw SodaException("잘못된 요청입니다.") val isLiveCreator = room.member!!.id == memberId val donationList = repository.getDonationList(roomId = room.id!!, isLiveCreator = isLiveCreator) + .filter { it.secretCan > 0 || it.can > 0 } val totalCan = donationList.sumOf { it.can } val totalSecretCan = donationList.sumOf { it.secretCan } -- 2.40.1