활성화된 룰렛 조회 로직 수정
This commit is contained in:
		| @@ -11,7 +11,6 @@ data class NewRoulette( | ||||
|     @Indexed | ||||
|     val creatorId: Long, | ||||
|     var can: Int, | ||||
|     @Indexed | ||||
|     var isActive: Boolean, | ||||
|     var items: List<RouletteItem> = mutableListOf() | ||||
| ) | ||||
|   | ||||
| @@ -4,5 +4,4 @@ import org.springframework.data.repository.CrudRepository | ||||
|  | ||||
| interface NewRouletteRepository : CrudRepository<NewRoulette, Long> { | ||||
|     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 { | ||||
|         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("룰렛을 사용할 수 없습니다.") | ||||
|         } | ||||
|  | ||||
|         return GetRouletteResponse( | ||||
|             can = roulette[0].can, | ||||
|             isActive = roulette[0].isActive, | ||||
|             items = roulette[0].items | ||||
|             can = activeRoulette.can, | ||||
|             isActive = activeRoulette.isActive, | ||||
|             items = activeRoulette.items | ||||
|         ) | ||||
|     } | ||||
|  | ||||
| @@ -148,23 +160,38 @@ class NewRouletteService( | ||||
|         } | ||||
|  | ||||
|         // 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("룰렛을 사용할 수 없습니다.") | ||||
|         } | ||||
|  | ||||
|         // STEP 3 - 캔 사용 | ||||
|         val roulette = rouletteList[0] | ||||
|         canPaymentService.spendCan( | ||||
|             memberId = memberId, | ||||
|             needCan = roulette.can, | ||||
|             needCan = activeRoulette.can, | ||||
|             canUsage = CanUsage.SPIN_ROULETTE, | ||||
|             liveRoom = room, | ||||
|             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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user