From 9c9d52f03ea716bc35d23ff76aeb0b8d622f8c0d Mon Sep 17 00:00:00 2001 From: dankito Date: Tue, 15 Oct 2024 10:17:22 +0200 Subject: [PATCH] Collecting MessageLog --- .../banking/ui/service/BankingService.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankingService.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankingService.kt index 9e53c12..b7c81a5 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankingService.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankingService.kt @@ -49,6 +49,8 @@ class BankingService( private val modelService = BankingModelService() + private val messageLog = mutableListOf() // TODO: make thread safe + private val log by logger() @@ -156,6 +158,9 @@ class BankingService( fun getTransaction(transactionId: Long) = bankingRepository.getTransactionById(transactionId) + fun getMessageLog() = messageLog.toList() + + suspend fun findBanks(query: String): List = bankFinder.findBankByNameBicBankCodeOrCity(query, 25) @@ -170,6 +175,8 @@ class BankingService( handleUnsuccessfulBankingClientResponse(BankingClientAction.AddAccount, bank.name, response) } + handleCommonBankingClientResponseValues(response) + return response.type == ResponseType.Success } catch (e: Throwable) { showAndLogError(ErroneousAction.AddAccount, "Could not add account for ${bank.name} $loginName", "Konto für ${bank.name} konnte nicht hinzugefügt werden", e) @@ -225,6 +232,9 @@ class BankingService( private suspend fun updateAccountTransactions(bank: BankAccessEntity, bankAccount: BankAccountEntity? = null) { try { val response = client.updateAccountTransactionsAsync(bank, bankAccount?.let { listOf(it) }) + + handleCommonBankingClientResponseValues(response) + if (response.type == ResponseType.Success && response.data != null) { handleSuccessfulUpdateAccountTransactionsResponse(bank, response.data!!) } else { @@ -395,6 +405,8 @@ class BankingService( paymentReference, instantTransfer )) + handleCommonBankingClientResponseValues(response) + if (response.error != null) { handleUnsuccessfulBankingClientResponse(BankingClientAction.TransferMoney, account.displayName, response) } else if (response.type == ResponseType.Success) { @@ -417,6 +429,12 @@ class BankingService( } } + private suspend fun handleCommonBankingClientResponseValues(response: Response<*>) { + withContext(Dispatchers.Main) { // dispatch to Main as messageLog is not synchronized + messageLog.addAll(response.messageLog) + } + } + private suspend fun updateOnChanges(uiSettings: UiSettings) { updateOnChanges(uiSettings, uiSettings.transactionsGrouping)