68 lines
2.5 KiB
Kotlin
68 lines
2.5 KiB
Kotlin
package kr.co.vividnext.sodalive.can
|
|
|
|
import kr.co.vividnext.sodalive.common.ApiResponse
|
|
import kr.co.vividnext.sodalive.common.SodaException
|
|
import kr.co.vividnext.sodalive.member.Member
|
|
import org.springframework.data.domain.Pageable
|
|
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.RequestParam
|
|
import org.springframework.web.bind.annotation.RestController
|
|
|
|
@RestController
|
|
@RequestMapping("/can")
|
|
class CanController(private val service: CanService) {
|
|
@GetMapping
|
|
fun getCans(
|
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
|
): ApiResponse<List<CanResponse>> {
|
|
val forcedCurrency = if (member != null && (member.id == 4L || member.id == 44144L)) {
|
|
"JPY"
|
|
} else {
|
|
null
|
|
}
|
|
return ApiResponse.ok(service.getCans(forcedCurrency = forcedCurrency))
|
|
}
|
|
|
|
@GetMapping("/status")
|
|
fun getCanStatus(
|
|
@RequestParam container: String,
|
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
|
) = run {
|
|
if (member == null) {
|
|
throw SodaException(messageKey = "common.error.bad_credentials")
|
|
}
|
|
|
|
ApiResponse.ok(service.getCanStatus(member, container))
|
|
}
|
|
|
|
@GetMapping("/status/use")
|
|
fun getCanUseStatus(
|
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?,
|
|
@RequestParam("timezone") timezone: String,
|
|
@RequestParam("container") container: String,
|
|
pageable: Pageable
|
|
) = run {
|
|
if (member == null) {
|
|
throw SodaException(messageKey = "common.error.bad_credentials")
|
|
}
|
|
|
|
ApiResponse.ok(service.getCanUseStatus(member, pageable, timezone, container))
|
|
}
|
|
|
|
@GetMapping("/status/charge")
|
|
fun getCanChargeStatus(
|
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?,
|
|
@RequestParam("timezone") timezone: String,
|
|
@RequestParam("container") container: String,
|
|
pageable: Pageable
|
|
) = run {
|
|
if (member == null) {
|
|
throw SodaException(messageKey = "common.error.bad_credentials")
|
|
}
|
|
|
|
ApiResponse.ok(service.getCanChargeStatus(member, pageable, timezone, container))
|
|
}
|
|
}
|