룰렛 업데이트
- 업데이트 하는 룰렛이 활성화 되는 경우 다른 룰렛 모두 비활성화
This commit is contained in:
		| @@ -86,18 +86,38 @@ class NewRouletteService( | ||||
|     fun updateRoulette(memberId: Long, request: UpdateNewRouletteRequest): Boolean { | ||||
|         rouletteValidate(can = request.can, items = request.items) | ||||
|  | ||||
|         val roulette = repository.findByIdOrNull(request.id) | ||||
|             ?: throw SodaException("잘못된 요청입니다.") | ||||
|         if (request.isActive) { | ||||
|             val rouletteList = repository.findByCreatorId(creatorId = memberId) | ||||
|  | ||||
|         if (roulette.creatorId != memberId) { | ||||
|             throw SodaException("잘못된 요청입니다.") | ||||
|             if (rouletteList.isEmpty()) { | ||||
|                 throw SodaException("잘못된 요청입니다.") | ||||
|             } | ||||
|  | ||||
|             rouletteList.forEach { | ||||
|                 if (it.id == request.id) { | ||||
|                     it.can = request.can | ||||
|                     it.items = request.items | ||||
|                     it.isActive = true | ||||
|                 } else { | ||||
|                     it.isActive = false | ||||
|                 } | ||||
|  | ||||
|                 repository.save(it) | ||||
|             } | ||||
|         } else { | ||||
|             val roulette = repository.findByIdOrNull(request.id) | ||||
|                 ?: throw SodaException("잘못된 요청입니다.") | ||||
|  | ||||
|             if (roulette.creatorId != memberId) { | ||||
|                 throw SodaException("잘못된 요청입니다.") | ||||
|             } | ||||
|  | ||||
|             roulette.can = request.can | ||||
|             roulette.items = request.items | ||||
|             roulette.isActive = false | ||||
|             repository.save(roulette) | ||||
|         } | ||||
|  | ||||
|         roulette.can = request.can | ||||
|         roulette.items = request.items | ||||
|         roulette.isActive = request.isActive | ||||
|         repository.save(roulette) | ||||
|  | ||||
|         return request.isActive | ||||
|     } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user