68 lines
1.6 KiB
Kotlin
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
|
|
)
|
|
}
|
|
}
|