fix🛠️: data transfer
This commit is contained in:
parent
0068f71977
commit
f2b955c7fc
|
@ -12,7 +12,7 @@ sealed class Resp<T> {
|
|||
override fun json() = RespData(code = 0, data = data, message = null)
|
||||
}
|
||||
|
||||
class Error(private val message: String?, val code: Int) : Resp<Unit>() {
|
||||
class Error(private val message: String?, val code: Int=-1) : Resp<Unit>() {
|
||||
override fun json(): RespData<Unit> = RespData(code = code, data = null, message = message)
|
||||
}
|
||||
|
||||
|
|
|
@ -4,9 +4,18 @@ import kotlinx.serialization.Serializable
|
|||
|
||||
|
||||
enum class BillType {
|
||||
Consume,
|
||||
Income,
|
||||
CONSUME,
|
||||
INCOME;
|
||||
|
||||
companion object {
|
||||
fun toType(n: Int): BillType = when (n) {
|
||||
0 -> CONSUME
|
||||
1 -> INCOME
|
||||
else -> throw IllegalArgumentException("error type $n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class Bill(
|
||||
var id: Int?,
|
||||
|
|
|
@ -41,10 +41,15 @@ fun Route.billRoute() {
|
|||
}
|
||||
}
|
||||
|
||||
delete("{id}") {
|
||||
delete("{id?}") {
|
||||
runCatching {
|
||||
val id = call.parameters.getOrFail("id").toInt()
|
||||
val count = billService.deleteOneBill(id)
|
||||
call.respond(status = HttpStatusCode.OK, Resp.Ok(count).json())
|
||||
billService.deleteOneBill(id)
|
||||
}.onSuccess {
|
||||
call.respond(status = HttpStatusCode.OK, Resp.Ok(it).json())
|
||||
}.onFailure {
|
||||
call.respond(Resp.Error(it.message).json())
|
||||
}
|
||||
}
|
||||
|
||||
put("/") {
|
||||
|
|
|
@ -3,6 +3,7 @@ package cn.fadinglight.vo
|
|||
import cn.fadinglight.models.Bill
|
||||
import cn.fadinglight.models.BillType
|
||||
import kotlinx.serialization.Serializable
|
||||
import java.util.*
|
||||
|
||||
@Serializable
|
||||
data class BillVO(
|
||||
|
@ -17,7 +18,7 @@ data class BillVO(
|
|||
|
||||
fun BillVO.bill() = Bill(
|
||||
id = id,
|
||||
type = BillType.valueOf(type),
|
||||
type = BillType.valueOf(type.uppercase(Locale.getDefault())),
|
||||
date = date,
|
||||
money = money,
|
||||
cls = cls,
|
||||
|
|
Loading…
Reference in New Issue
Block a user