|
@@ -12,21 +12,27 @@ import dev.samstevens.totp.secret.DefaultSecretGenerator
|
|
import dev.samstevens.totp.time.SystemTimeProvider
|
|
import dev.samstevens.totp.time.SystemTimeProvider
|
|
import dev.samstevens.totp.time.TimeProvider
|
|
import dev.samstevens.totp.time.TimeProvider
|
|
import dev.samstevens.totp.util.Utils.getDataUriForImage
|
|
import dev.samstevens.totp.util.Utils.getDataUriForImage
|
|
-import inn.ocsf.bee.freigeld.core.model.CentralBank
|
|
|
|
-import inn.ocsf.bee.freigeld.core.model.GlobalWorld
|
|
|
|
-import inn.ocsf.bee.freigeld.core.model.PersonIdentityFullName
|
|
|
|
-import inn.ocsf.bee.freigeld.core.model.PersonIdentitySecret
|
|
|
|
|
|
+import inn.ocsf.bee.freigeld.core.data.CentralBankQueueLevel
|
|
|
|
+import inn.ocsf.bee.freigeld.core.data.ExchangeFailedEvent
|
|
|
|
+import inn.ocsf.bee.freigeld.core.data.ExchangeSuccessEvent
|
|
|
|
+import inn.ocsf.bee.freigeld.core.demo.getSelfAccount
|
|
|
|
+import inn.ocsf.bee.freigeld.core.model.*
|
|
import inn.ocsf.bee.freigeld.core.model.data.PersonData
|
|
import inn.ocsf.bee.freigeld.core.model.data.PersonData
|
|
import inn.ocsf.bee.freigeld.core.repo.PersonRepository
|
|
import inn.ocsf.bee.freigeld.core.repo.PersonRepository
|
|
|
|
+import inn.ocsf.bee.freigeld.core.repo.PublicLinkRepository
|
|
|
|
+import inn.ocsf.bee.freigeld.core.service.TicketService
|
|
import inn.ocsf.bee.freigeld.serve.JwtAuthenticationController
|
|
import inn.ocsf.bee.freigeld.serve.JwtAuthenticationController
|
|
import inn.ocsf.bee.freigeld.utils.KeyValueBucket.personToSite
|
|
import inn.ocsf.bee.freigeld.utils.KeyValueBucket.personToSite
|
|
import inn.ocsf.bee.freigeld.utils.KeyValueBucket.secretToSite
|
|
import inn.ocsf.bee.freigeld.utils.KeyValueBucket.secretToSite
|
|
import inn.ocsf.bee.freigeld.utils.KeyValueStorage
|
|
import inn.ocsf.bee.freigeld.utils.KeyValueStorage
|
|
import org.apache.commons.lang3.RandomStringUtils
|
|
import org.apache.commons.lang3.RandomStringUtils
|
|
|
|
+import org.slf4j.LoggerFactory
|
|
|
|
+import org.springframework.context.annotation.Profile
|
|
import org.springframework.http.ResponseEntity
|
|
import org.springframework.http.ResponseEntity
|
|
import org.springframework.web.bind.annotation.*
|
|
import org.springframework.web.bind.annotation.*
|
|
import java.util.*
|
|
import java.util.*
|
|
import javax.inject.Inject
|
|
import javax.inject.Inject
|
|
|
|
+import kotlin.streams.toList
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
class PersonController {
|
|
class PersonController {
|
|
@@ -37,21 +43,92 @@ class PersonController {
|
|
@Inject
|
|
@Inject
|
|
private lateinit var bank: CentralBank
|
|
private lateinit var bank: CentralBank
|
|
|
|
|
|
|
|
+ @Inject
|
|
|
|
+ private lateinit var ticketService: TicketService
|
|
|
|
+
|
|
|
|
+ @Inject
|
|
|
|
+ private lateinit var linkRepo: PublicLinkRepository
|
|
|
|
+
|
|
|
|
+ private val log = LoggerFactory.getLogger(javaClass)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @RequestMapping("api/old/person/{personId}/account/{accountId}/debit-by-link", method = [RequestMethod.POST])
|
|
|
|
+ fun getDebitLink(@PathVariable("personId") personId: UUID, @PathVariable("accountId") accountId: UUID, @RequestBody lreq: DebitLinkReq): ResponseEntity<Map<String, Any>> {
|
|
|
|
+ val link = linkRepo.getFreeIdAndSave { id -> PublicLinkDebitAccount(id, personId, accountId, lreq.amount, lreq.once, lreq.time) }
|
|
|
|
+ return ResponseEntity.ok(mapOf("code" to link.id)) //p7do
|
|
|
|
+ }
|
|
|
|
+
|
|
@RequestMapping("api/old/person/{personId}/accounts", method = [RequestMethod.GET])
|
|
@RequestMapping("api/old/person/{personId}/accounts", method = [RequestMethod.GET])
|
|
fun getAccountsInfo(@PathVariable("personId") personId: UUID): ResponseEntity<Map<String, Any?>> {
|
|
fun getAccountsInfo(@PathVariable("personId") personId: UUID): ResponseEntity<Map<String, Any?>> {
|
|
val accounts = bank.getAccounts(personId).map { AccountInfo(it.id, it.overall) }
|
|
val accounts = bank.getAccounts(personId).map { AccountInfo(it.id, it.overall) }
|
|
return ResponseEntity.ok(mapOf("accounts" to accounts))
|
|
return ResponseEntity.ok(mapOf("accounts" to accounts))
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @RequestMapping("api/old/person/{personId}/events", method = [RequestMethod.GET])
|
|
|
|
+ fun getEvents(@PathVariable("personId") personId: UUID, @RequestParam("limit", defaultValue = "25") limit: Long, @RequestParam("after", required = false) eventId: UUID?): ResponseEntity<List<AccountEvent>> {
|
|
|
|
+ val accounts = bank.getAccounts(personId).map { it.id }
|
|
|
|
+ var skipping = eventId != null
|
|
|
|
+ val events = ticketService.findAll(CentralBankQueueLevel.bankTicketChannelName, setOf(TicketStatus.completed)).filter {
|
|
|
|
+ val skippingThis = skipping
|
|
|
|
+ if (skipping) if (it.ticket.id == eventId) skipping = false
|
|
|
|
+ !skippingThis
|
|
|
|
+ }.filter {
|
|
|
|
+ val ticket = it.ticket
|
|
|
|
+ val ids = when (ticket) {
|
|
|
|
+ is ExchangeFailedEvent -> setOf(ticket.parentEvent?.from, ticket.parentEvent?.to)
|
|
|
|
+ is ExchangeSuccessEvent -> setOf(ticket.parentEvent?.from, ticket.parentEvent?.to)
|
|
|
|
+ else -> setOf()
|
|
|
|
+ }
|
|
|
|
+ accounts.intersect(ids).isNotEmpty()
|
|
|
|
+ }.map {
|
|
|
|
+ val ticket = it.ticket as BankEvent
|
|
|
|
+ AccountEvent(it.ticket.id, it.ticket::class.java.typeName, it.ts.time, ticket)
|
|
|
|
+ }.limit(limit).toList().sortedByDescending { it.ts }
|
|
|
|
+ return ResponseEntity.ok(events)
|
|
|
|
+ }
|
|
|
|
+
|
|
@RequestMapping("api/old/person/{personId}/accounts/add", method = [RequestMethod.POST])
|
|
@RequestMapping("api/old/person/{personId}/accounts/add", method = [RequestMethod.POST])
|
|
fun addAccount(@PathVariable("personId") personId: UUID): ResponseEntity<Map<String, Any?>> {
|
|
fun addAccount(@PathVariable("personId") personId: UUID): ResponseEntity<Map<String, Any?>> {
|
|
val account = bank.addAccount(personId)
|
|
val account = bank.addAccount(personId)
|
|
return ResponseEntity.ok(mapOf("id" to account.id))
|
|
return ResponseEntity.ok(mapOf("id" to account.id))
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Profile("dev")
|
|
|
|
+ @RequestMapping("api/old/person/{personId}/givemoney", method = [RequestMethod.POST])
|
|
|
|
+ fun giveMoney(@PathVariable("personId") personId: UUID): ResponseEntity<Map<String, Any?>> {
|
|
|
|
+ val account = bank.getAccounts(personId).random()
|
|
|
|
+ bank.exchange(account, bank.getSelfAccount(), (100 * Math.random()).toLong()).get()
|
|
|
|
+ return ResponseEntity.ok(mapOf())
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+data class DebitLinkReq(val amount: Long?, val once: Boolean?, val time: Long?)
|
|
|
|
+
|
|
data class AccountInfo(val id: UUID, val overall: Long)
|
|
data class AccountInfo(val id: UUID, val overall: Long)
|
|
|
|
|
|
|
|
+data class AccountEvent(val id: UUID, val type: String, val ts: Long, val info: BankEvent)
|
|
|
|
+
|
|
|
|
+class PublicLinkDebitAccount() : PublicLink() {
|
|
|
|
+
|
|
|
|
+ var personId: UUID? = null
|
|
|
|
+ var accountId: UUID? = null
|
|
|
|
+ var amount: Long? = null
|
|
|
|
+ var once: Boolean? = null
|
|
|
|
+ var time: Long? = null
|
|
|
|
+ var dt: Date? = null
|
|
|
|
+
|
|
|
|
+ constructor(id: String, personId: UUID, accountId: UUID, amount: Long?, once: Boolean?, time: Long?) : this() {
|
|
|
|
+ this.id = id
|
|
|
|
+ this.personId = personId
|
|
|
|
+ this.accountId = accountId
|
|
|
|
+ this.amount = amount
|
|
|
|
+ this.once = once
|
|
|
|
+ this.time = time
|
|
|
|
+ this.dt = Date()
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
@RestController
|
|
@RestController
|
|
@CrossOrigin
|
|
@CrossOrigin
|
|
class PersonAuthController : JwtAuthenticationController() {
|
|
class PersonAuthController : JwtAuthenticationController() {
|