- 추가 슬롯 개수와 가격 조회 기능 추가
This commit is contained in:
Klaus 2024-07-25 21:28:17 +09:00
parent 77a9f1a13c
commit abb60f5743
5 changed files with 82 additions and 1 deletions

View File

@ -0,0 +1,24 @@
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.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!!)
)
}
}

View File

@ -0,0 +1,22 @@
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
}
}

View File

@ -0,0 +1,31 @@
package kr.co.vividnext.sodalive.alarm
import org.springframework.stereotype.Service
@Service
class AlarmService(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
}
}
)
}
}

View File

@ -0,0 +1,3 @@
package kr.co.vividnext.sodalive.alarm
data class GetSlotQuantityAndPriceResponse(val slotQuantity: Int, val price: Int)

View File

@ -6,5 +6,6 @@ enum class CanUsage {
CHANGE_NICKNAME,
ORDER_CONTENT,
SPIN_ROULETTE,
PAID_COMMUNITY_POST
PAID_COMMUNITY_POST,
ALARM_SLOT
}