diff options
author | MS <ms@taler.net> | 2023-01-20 14:49:47 +0100 |
---|---|---|
committer | MS <ms@taler.net> | 2023-01-20 16:39:58 +0100 |
commit | b28f1511dab120ef2bfeef39801a0058c543138b (patch) | |
tree | 74bc134b335356a23ea24d0ad95d0c8475db2642 /sandbox/src/main/kotlin/tech/libeufin | |
parent | 1e1464497948747c59c3b0fcf859c257b6ea212e (diff) | |
download | libeufin-b28f1511dab120ef2bfeef39801a0058c543138b.tar.gz libeufin-b28f1511dab120ef2bfeef39801a0058c543138b.tar.bz2 libeufin-b28f1511dab120ef2bfeef39801a0058c543138b.zip |
Circuit API.
Storing and showing more details about a cash-out
operation -- used to be only the state.
Avoiding showing accounts not added via the Circuit
API along its "GET /accounts" response.
Diffstat (limited to 'sandbox/src/main/kotlin/tech/libeufin')
-rw-r--r-- | sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt | 43 | ||||
-rw-r--r-- | sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt | 2 |
2 files changed, 43 insertions, 2 deletions
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt index 0c43dd29..a6e97778 100644 --- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt +++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt @@ -1,5 +1,6 @@ package tech.libeufin.sandbox +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import io.ktor.server.application.* import io.ktor.http.* import io.ktor.server.request.* @@ -262,7 +263,32 @@ fun circuitApi(circuitRoute: Route) { } if (maybeOperation == null) throw notFound("Cash-out operation $operationUuid not found.") - call.respond(object { val status = maybeOperation.state }) + call.respond(object { + val status = maybeOperation.state + val amount_credit = maybeOperation.amountCredit + val amount_debit = maybeOperation.amountDebit + val subject = maybeOperation.subject + val creation_time = maybeOperation.creationTime.toString() + val cashout_address = maybeOperation.tanChannel + val account = maybeOperation.account + }) + return@get + } + // Gets the list of all the cash-out operations. + circuitRoute.get("/cashouts") { + call.request.basicAuth(onlyAdmin = true) + val node = jacksonObjectMapper().createObjectNode() + val maybeArray = node.putArray("cashouts") + transaction { + CashoutOperationEntity.all().forEach { + maybeArray.add(it.uuid.toString()) + } + } + if (maybeArray.size() == 0) { + call.respond(HttpStatusCode.NoContent) + return@get + } + call.respond(node) return@get } // Create a cash-out operation. @@ -325,8 +351,9 @@ fun circuitApi(circuitRoute: Route) { val op = transaction { CashoutOperationEntity.new { this.amountDebit = req.amount_debit + this.amountCredit = req.amount_credit this.subject = cashoutSubject - this.creationTime = getUTCnow().toInstant().epochSecond + this.creationTime = getUTCnow().toInstant().toEpochMilli() this.tanChannel = tanChannel this.account = user this.tan = getRandomString(5) @@ -395,6 +422,11 @@ fun circuitApi(circuitRoute: Route) { throwIfInstitutionalName(resourceName) allowOwnerOrAdmin(username, resourceName) val customer = getCustomer(resourceName) + /** FIXME: the following query can 404, but should 500. + * The reason is that that's the bank's fault if an existing + * customer misses the bank account. Check other calls too, + * for the same error. + */ val bankAccount = getBankAccountFromLabel(resourceName) /** * Throwing when name or cash-out address aren't found ensures @@ -420,6 +452,13 @@ fun circuitApi(circuitRoute: Route) { val customers = mutableListOf<Any>() transaction { DemobankCustomerEntity.all().forEach { + if (it.cashout_address == null) { + logger.debug("Not listing account '${it.username}', as that" + + " misses the cash-out address " + + "and therefore doesn't belong to the Circuit API" + ) + return@forEach + } customers.add(object { val username = it.username val name = it.name diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt index f1eba15a..3adb1a27 100644 --- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt +++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt @@ -440,6 +440,7 @@ object CashoutOperationsTable : LongIdTable() { * local currency bank account. */ val amountDebit = text("amountDebit") + val amountCredit = text("amountCredit") val subject = text("subject") val creationTime = long("creationTime") // in seconds. val tanChannel = text("tanChannel") @@ -452,6 +453,7 @@ class CashoutOperationEntity(id: EntityID<Long>) : LongEntity(id) { companion object : LongEntityClass<CashoutOperationEntity>(CashoutOperationsTable) var uuid by CashoutOperationsTable.uuid var amountDebit by CashoutOperationsTable.amountDebit + var amountCredit by CashoutOperationsTable.amountCredit var subject by CashoutOperationsTable.subject var creationTime by CashoutOperationsTable.creationTime var tanChannel by CashoutOperationsTable.tanChannel |