Compare commits
No commits in common. "2cdbbb1b37748c6d5a2c302dd32fec1ceae3ce5c" and "4dce8c8f03e130ac2287200e5b427d3b1d711348" have entirely different histories.
2cdbbb1b37
...
4dce8c8f03
|
@ -1,41 +0,0 @@
|
||||||
package kr.co.vividnext.sodalive.alarm
|
|
||||||
|
|
||||||
import kr.co.vividnext.sodalive.common.ApiResponse
|
|
||||||
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
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/alarm")
|
|
||||||
class AlarmController(private val service: AlarmService) {
|
|
||||||
@GetMapping
|
|
||||||
fun getSlotQuantityAndPrice(
|
|
||||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
|
||||||
) = run {
|
|
||||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
|
||||||
|
|
||||||
ApiResponse.ok(
|
|
||||||
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
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
package kr.co.vividnext.sodalive.alarm
|
|
||||||
|
|
||||||
import com.querydsl.jpa.impl.JPAQueryFactory
|
|
||||||
import kr.co.vividnext.sodalive.can.use.CanUsage
|
|
||||||
import kr.co.vividnext.sodalive.can.use.QUseCan.useCan
|
|
||||||
import org.springframework.stereotype.Repository
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
class AlarmRepository(private val queryFactory: JPAQueryFactory) {
|
|
||||||
fun getSlotQuantity(memberId: Long): Int {
|
|
||||||
return queryFactory
|
|
||||||
.select(useCan.id)
|
|
||||||
.from(useCan)
|
|
||||||
.where(
|
|
||||||
useCan.member.id.eq(memberId)
|
|
||||||
.and(useCan.isRefund.isFalse)
|
|
||||||
.and(useCan.canUsage.eq(CanUsage.ALARM_SLOT))
|
|
||||||
)
|
|
||||||
.fetch()
|
|
||||||
.size
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
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
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
package kr.co.vividnext.sodalive.alarm
|
|
||||||
|
|
||||||
data class GetSlotQuantityAndPriceResponse(val slotQuantity: Int, val price: Int)
|
|
|
@ -68,7 +68,6 @@ class CanService(private val repository: CanRepository) {
|
||||||
}
|
}
|
||||||
|
|
||||||
CanUsage.CHANGE_NICKNAME -> "닉네임 변경"
|
CanUsage.CHANGE_NICKNAME -> "닉네임 변경"
|
||||||
CanUsage.ALARM_SLOT -> "알람 슬롯 구매"
|
|
||||||
CanUsage.ORDER_CONTENT -> "[콘텐츠 구매] ${it.audioContent!!.title}"
|
CanUsage.ORDER_CONTENT -> "[콘텐츠 구매] ${it.audioContent!!.title}"
|
||||||
CanUsage.PAID_COMMUNITY_POST -> "[게시글 보기] ${it.communityPost?.member?.nickname ?: ""}"
|
CanUsage.PAID_COMMUNITY_POST -> "[게시글 보기] ${it.communityPost?.member?.nickname ?: ""}"
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,8 +96,6 @@ class CanPaymentService(
|
||||||
recipientId = communityPost.member!!.id!!
|
recipientId = communityPost.member!!.id!!
|
||||||
useCan.communityPost = communityPost
|
useCan.communityPost = communityPost
|
||||||
useCan.member = member
|
useCan.member = member
|
||||||
} else if (canUsage == CanUsage.ALARM_SLOT) {
|
|
||||||
useCan.member = member
|
|
||||||
} else {
|
} else {
|
||||||
throw SodaException("잘못된 요청입니다.")
|
throw SodaException("잘못된 요청입니다.")
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,5 @@ enum class CanUsage {
|
||||||
CHANGE_NICKNAME,
|
CHANGE_NICKNAME,
|
||||||
ORDER_CONTENT,
|
ORDER_CONTENT,
|
||||||
SPIN_ROULETTE,
|
SPIN_ROULETTE,
|
||||||
PAID_COMMUNITY_POST,
|
PAID_COMMUNITY_POST
|
||||||
ALARM_SLOT
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue