활성화된 룰렛 조회 로직 수정
This commit is contained in:
parent
0e9863050f
commit
bcd094c5dd
|
@ -11,7 +11,6 @@ data class NewRoulette(
|
||||||
@Indexed
|
@Indexed
|
||||||
val creatorId: Long,
|
val creatorId: Long,
|
||||||
var can: Int,
|
var can: Int,
|
||||||
@Indexed
|
|
||||||
var isActive: Boolean,
|
var isActive: Boolean,
|
||||||
var items: List<RouletteItem> = mutableListOf()
|
var items: List<RouletteItem> = mutableListOf()
|
||||||
)
|
)
|
||||||
|
|
|
@ -4,5 +4,4 @@ import org.springframework.data.repository.CrudRepository
|
||||||
|
|
||||||
interface NewRouletteRepository : CrudRepository<NewRoulette, Long> {
|
interface NewRouletteRepository : CrudRepository<NewRoulette, Long> {
|
||||||
fun findByCreatorId(creatorId: Long): List<NewRoulette>
|
fun findByCreatorId(creatorId: Long): List<NewRoulette>
|
||||||
fun findByCreatorIdAndActive(creatorId: Long, isActive: Boolean): List<NewRoulette>
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,16 +122,28 @@ class NewRouletteService(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getRoulette(creatorId: Long, memberId: Long): GetRouletteResponse {
|
fun getRoulette(creatorId: Long, memberId: Long): GetRouletteResponse {
|
||||||
val roulette = repository.findByCreatorIdAndActive(creatorId = creatorId, isActive = true)
|
val rouletteList = repository.findByCreatorId(creatorId = creatorId)
|
||||||
|
|
||||||
if (roulette.isEmpty() || !roulette[0].isActive || roulette[0].items.isEmpty()) {
|
if (rouletteList.isEmpty()) {
|
||||||
|
throw SodaException("룰렛을 사용할 수 없습니다.")
|
||||||
|
}
|
||||||
|
|
||||||
|
var activeRoulette: NewRoulette? = null
|
||||||
|
for (roulette in rouletteList) {
|
||||||
|
if (roulette.isActive) {
|
||||||
|
activeRoulette = roulette
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (activeRoulette == null || activeRoulette.items.isEmpty()) {
|
||||||
throw SodaException("룰렛을 사용할 수 없습니다.")
|
throw SodaException("룰렛을 사용할 수 없습니다.")
|
||||||
}
|
}
|
||||||
|
|
||||||
return GetRouletteResponse(
|
return GetRouletteResponse(
|
||||||
can = roulette[0].can,
|
can = activeRoulette.can,
|
||||||
isActive = roulette[0].isActive,
|
isActive = activeRoulette.isActive,
|
||||||
items = roulette[0].items
|
items = activeRoulette.items
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,23 +160,38 @@ class NewRouletteService(
|
||||||
}
|
}
|
||||||
|
|
||||||
// STEP 2 - 룰렛 데이터 가져오기
|
// STEP 2 - 룰렛 데이터 가져오기
|
||||||
val rouletteList = repository.findByCreatorIdAndActive(creatorId = host.id!!, isActive = true)
|
val rouletteList = repository.findByCreatorId(creatorId = host.id!!)
|
||||||
|
|
||||||
if (rouletteList.isEmpty() || !rouletteList[0].isActive || rouletteList[0].items.isEmpty()) {
|
if (rouletteList.isEmpty()) {
|
||||||
|
throw SodaException("룰렛을 사용할 수 없습니다.")
|
||||||
|
}
|
||||||
|
|
||||||
|
var activeRoulette: NewRoulette? = null
|
||||||
|
for (roulette in rouletteList) {
|
||||||
|
if (roulette.isActive) {
|
||||||
|
activeRoulette = roulette
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (activeRoulette == null || activeRoulette.items.isEmpty()) {
|
||||||
throw SodaException("룰렛을 사용할 수 없습니다.")
|
throw SodaException("룰렛을 사용할 수 없습니다.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// STEP 3 - 캔 사용
|
// STEP 3 - 캔 사용
|
||||||
val roulette = rouletteList[0]
|
|
||||||
canPaymentService.spendCan(
|
canPaymentService.spendCan(
|
||||||
memberId = memberId,
|
memberId = memberId,
|
||||||
needCan = roulette.can,
|
needCan = activeRoulette.can,
|
||||||
canUsage = CanUsage.SPIN_ROULETTE,
|
canUsage = CanUsage.SPIN_ROULETTE,
|
||||||
liveRoom = room,
|
liveRoom = room,
|
||||||
container = request.container
|
container = request.container
|
||||||
)
|
)
|
||||||
|
|
||||||
return GetRouletteResponse(can = roulette.can, isActive = roulette.isActive, items = roulette.items)
|
return GetRouletteResponse(
|
||||||
|
can = activeRoulette.can,
|
||||||
|
isActive = activeRoulette.isActive,
|
||||||
|
items = activeRoulette.items
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
|
Loading…
Reference in New Issue