라이브 - 후원현황 API

- 방장은 비밀후원 내역도 반영되도록 수정
This commit is contained in:
Klaus 2024-09-20 01:04:02 +09:00
parent dd0b751a43
commit 2c4c19990a
3 changed files with 32 additions and 22 deletions

View File

@ -162,7 +162,7 @@ class LiveRoomController(
) = run { ) = run {
if (member == null) throw SodaException("로그인 정보를 확인해주세요.") if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
ApiResponse.ok(service.getDonationTotal(roomId)) ApiResponse.ok(service.getDonationTotal(roomId, memberId = member.id!!))
} }
@PutMapping("/info/set/speaker") @PutMapping("/info/set/speaker")
@ -232,7 +232,7 @@ class LiveRoomController(
) = run { ) = run {
if (member == null) throw SodaException("로그인 정보를 확인해주세요.") if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
ApiResponse.ok(service.getDonationStatus(roomId)) ApiResponse.ok(service.getDonationStatus(roomId, memberId = member.id!!))
} }
@PostMapping("/quit") @PostMapping("/quit")

View File

@ -49,8 +49,8 @@ interface LiveRoomQueryRepository {
fun getLiveRoom(id: Long): LiveRoom? fun getLiveRoom(id: Long): LiveRoom?
fun getLiveRoomAndAccountId(roomId: Long, memberId: Long): LiveRoom? fun getLiveRoomAndAccountId(roomId: Long, memberId: Long): LiveRoom?
fun getRecentRoomInfo(memberId: Long): GetRecentRoomInfoResponse? fun getRecentRoomInfo(memberId: Long): GetRecentRoomInfoResponse?
fun getDonationTotal(roomId: Long): Int? fun getDonationTotal(roomId: Long, isLiveCreator: Boolean): Int?
fun getDonationList(roomId: Long): List<GetLiveRoomDonationItem> fun getDonationList(roomId: Long, isLiveCreator: Boolean): List<GetLiveRoomDonationItem>
fun getRoomActiveAndChannelNameIsNotNull(memberId: Long): List<LiveRoom> fun getRoomActiveAndChannelNameIsNotNull(memberId: Long): List<LiveRoom>
} }
@ -225,22 +225,33 @@ class LiveRoomQueryRepositoryImpl(
.fetchFirst() .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 return queryFactory
.select(useCanCalculate.can.sum()) .select(useCanCalculate.can.sum())
.from(useCanCalculate) .from(useCanCalculate)
.innerJoin(useCanCalculate.useCan, useCan) .innerJoin(useCanCalculate.useCan, useCan)
.innerJoin(useCan.room, liveRoom) .innerJoin(useCan.room, liveRoom)
.where( .where(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)
)
.fetchOne() .fetchOne()
} }
override fun getDonationList(roomId: Long): List<GetLiveRoomDonationItem> { override fun getDonationList(roomId: Long, isLiveCreator: Boolean): List<GetLiveRoomDonationItem> {
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 return queryFactory
.select( .select(
QGetLiveRoomDonationItem( QGetLiveRoomDonationItem(
@ -256,12 +267,7 @@ class LiveRoomQueryRepositoryImpl(
.from(useCan) .from(useCan)
.join(useCan.member, member) .join(useCan.member, member)
.groupBy(useCan.member) .groupBy(useCan.member)
.where( .where(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)
)
.orderBy(useCan.can.sum().add(useCan.rewardCan.sum()).desc()) .orderBy(useCan.can.sum().add(useCan.rewardCan.sum()).desc())
.fetch() .fetch()
} }

View File

@ -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( 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 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 } val totalCan = donationList.sumOf { it.can }
return GetLiveRoomDonationStatusResponse( return GetLiveRoomDonationStatusResponse(