Files
sodalive-backend-spring-boot/src/main/kotlin/kr/co/vividnext/sodalive/alarm/AlarmService.kt
Klaus 766d9668c2 알람
- 추가 슬롯 구매 기능 추가
2024-07-25 21:53:29 +09:00

68 lines
1.6 KiB
Kotlin

package kr.co.vividnext.sodalive.alarm
import kr.co.vividnext.sodalive.can.payment.CanPaymentService
import kr.co.vividnext.sodalive.can.use.CanUsage
import kr.co.vividnext.sodalive.common.SodaException
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
@Service
class AlarmService(
private val canPaymentService: CanPaymentService,
private val repository: AlarmRepository
) {
fun getSlotQuantityAndPrice(memberId: Long): GetSlotQuantityAndPriceResponse {
val slotQuantity = repository.getSlotQuantity(memberId)
return GetSlotQuantityAndPriceResponse(
slotQuantity = slotQuantity,
price = when (slotQuantity) {
0 -> {
30
}
1 -> {
60
}
2 -> {
100
}
else -> {
0
}
}
)
}
@Transactional
fun buyExtraSlot(memberId: Long, container: String) {
val slotQuantity = repository.getSlotQuantity(memberId)
val needCan = when (slotQuantity) {
0 -> {
30
}
1 -> {
60
}
2 -> {
100
}
else -> {
throw SodaException("이미 구매하셨습니다")
}
}
canPaymentService.spendCan(
memberId = memberId,
needCan = needCan,
canUsage = CanUsage.ALARM_SLOT,
container = container
)
}
}