- 추가 슬롯 구매 기능 추가
This commit is contained in:
Klaus 2024-07-25 21:53:29 +09:00
parent abb60f5743
commit 766d9668c2
3 changed files with 56 additions and 1 deletions

View File

@ -5,6 +5,8 @@ import kr.co.vividnext.sodalive.common.SodaException
import kr.co.vividnext.sodalive.member.Member
import org.springframework.security.core.annotation.AuthenticationPrincipal
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
@ -21,4 +23,19 @@ class AlarmController(private val service: AlarmService) {
service.getSlotQuantityAndPrice(memberId = member.id!!)
)
}
@PostMapping("/buy-slot/{container}")
fun buyExtraSlot(
@PathVariable("container") container: String,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
ApiResponse.ok(
service.buyExtraSlot(
memberId = member.id!!,
container = container
)
)
}
}

View File

@ -1,9 +1,16 @@
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 repository: AlarmRepository) {
class AlarmService(
private val canPaymentService: CanPaymentService,
private val repository: AlarmRepository
) {
fun getSlotQuantityAndPrice(memberId: Long): GetSlotQuantityAndPriceResponse {
val slotQuantity = repository.getSlotQuantity(memberId)
@ -28,4 +35,33 @@ class AlarmService(private val repository: AlarmRepository) {
}
)
}
@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
)
}
}

View File

@ -96,6 +96,8 @@ class CanPaymentService(
recipientId = communityPost.member!!.id!!
useCan.communityPost = communityPost
useCan.member = member
} else if (canUsage == CanUsage.ALARM_SLOT) {
useCan.member = member
} else {
throw SodaException("잘못된 요청입니다.")
}