fix🛠️: data transfer

This commit is contained in:
车厘子 2022-11-18 00:31:09 +08:00
parent 0068f71977
commit f2b955c7fc
4 changed files with 23 additions and 8 deletions

View File

@ -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)
}

View File

@ -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?,

View File

@ -41,10 +41,15 @@ fun Route.billRoute() {
}
}
delete("{id}") {
val id = call.parameters.getOrFail("id").toInt()
val count = billService.deleteOneBill(id)
call.respond(status = HttpStatusCode.OK, Resp.Ok(count).json())
delete("{id?}") {
runCatching {
val id = call.parameters.getOrFail("id").toInt()
billService.deleteOneBill(id)
}.onSuccess {
call.respond(status = HttpStatusCode.OK, Resp.Ok(it).json())
}.onFailure {
call.respond(Resp.Error(it.message).json())
}
}
put("/") {

View File

@ -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,