diff --git a/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/BankingRepository.kt b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/BankingRepository.kt index f6b3665..ad6dd0b 100644 --- a/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/BankingRepository.kt +++ b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/BankingRepository.kt @@ -31,6 +31,8 @@ interface BankingRepository { suspend fun updateBank(bank: BankAccessEntity, loginName: String, password: String, bankName: String?) + suspend fun updateBank(bank: BankAccessEntity, clientData: String?) + suspend fun updateAccount(account: BankAccountEntity, userSetDisplayName: String?, hideAccount: Boolean, includeInAutomaticAccountsUpdate: Boolean) suspend fun updateAccount(account: BankAccountEntity, balance: Amount, lastAccountUpdateTime: Instant, retrievedTransactionsFrom: LocalDate?) diff --git a/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/InMemoryBankingRepository.kt b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/InMemoryBankingRepository.kt index 1e1aeb5..97a835a 100644 --- a/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/InMemoryBankingRepository.kt +++ b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/InMemoryBankingRepository.kt @@ -55,6 +55,10 @@ class InMemoryBankingRepository( // no-op } + override suspend fun updateBank(bank: BankAccessEntity, clientData: String?) { + // no-op + } + override suspend fun updateAccount(account: BankAccountEntity, userSetDisplayName: String?, hideAccount: Boolean, includeInAutomaticAccountsUpdate: Boolean) { // no-op } diff --git a/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/SqliteBankingRepository.kt b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/SqliteBankingRepository.kt index e730e84..b0087d0 100644 --- a/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/SqliteBankingRepository.kt +++ b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/SqliteBankingRepository.kt @@ -97,7 +97,7 @@ open class SqliteBankingRepository : BankingRepository { return bankQueries.getAllBanks { id, domesticBankCode, loginName, password, bankName, bic, customerName, userId, selectedTanMethodIdentifier, selectedTanMediumIdentifier, bankingGroup, serverAddress, countryCode, clientData, userSetDisplayName, displayIndex, iconUrl, wrongCredentialsEntered -> BankAccessEntity(id, domesticBankCode, loginName, password, bankName, bic, customerName, userId, getAccountsOfBank(id, bankAccounts, holdings), selectedTanMethodIdentifier, tanMethods[id] ?: mutableListOf(), selectedTanMediumIdentifier, tanMedia[id] ?: mutableListOf(), - bankingGroup?.let { BankingGroup.valueOf(it) }, serverAddress, countryCode, userSetDisplayName, displayIndex.toInt(), iconUrl, wrongCredentialsEntered) + bankingGroup?.let { BankingGroup.valueOf(it) }, serverAddress, countryCode, userSetDisplayName, displayIndex.toInt(), iconUrl, wrongCredentialsEntered, clientData) }.executeAsList() } @@ -111,7 +111,7 @@ open class SqliteBankingRepository : BankingRepository { return bankQueries.transactionWithResult { bankQueries.insertBank(bank.domesticBankCode, bank.loginName, bank.password, bank.bankName, bank.bic, bank.customerName, bank.userId, bank.selectedTanMethodIdentifier, bank.selectedTanMediumIdentifier, - bank.bankingGroup?.name, bank.serverAddress, bank.countryCode, null, bank.userSetDisplayName, bank.displayIndex.toLong(), bank.iconUrl, bank.wrongCredentialsEntered + bank.bankingGroup?.name, bank.serverAddress, bank.countryCode, bank.clientData, bank.userSetDisplayName, bank.displayIndex.toLong(), bank.iconUrl, bank.wrongCredentialsEntered ) val bankId = getLastInsertedId() // getLastInsertedId() / last_insert_rowid() has to be called in a transaction with the insert operation, otherwise it will not work @@ -141,6 +141,14 @@ open class SqliteBankingRepository : BankingRepository { } } + override suspend fun updateBank(bank: BankAccessEntity, clientData: String?) { + bankQueries.transaction { + if (clientData != null) { + bankQueries.updateBankClientData(clientData, bank.id) + } + } + } + override suspend fun updateAccount(account: BankAccountEntity, userSetDisplayName: String?, hideAccount: Boolean, includeInAutomaticAccountsUpdate: Boolean) { bankQueries.transaction { if (account.userSetDisplayName != userSetDisplayName) { diff --git a/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/entities/BankAccessEntity.kt b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/entities/BankAccessEntity.kt index 819eb70..718a931 100644 --- a/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/entities/BankAccessEntity.kt +++ b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/entities/BankAccessEntity.kt @@ -32,7 +32,9 @@ class BankAccessEntity( displayIndex: Int = 0, iconUrl: String? = null, - wrongCredentialsEntered: Boolean = false + wrongCredentialsEntered: Boolean = false, + + clientData: String? = null ) : BankAccess(domesticBankCode, loginName, password, bankName, bic, customerName, userId, accounts, selectedTanMethodIdentifier, tanMethods, selectedTanMediumIdentifier, tanMedia, bankingGroup, serverAddress, countryCode) { init { @@ -41,6 +43,8 @@ class BankAccessEntity( this.iconUrl = iconUrl this.wrongCredentialsEntered = wrongCredentialsEntered + + this.clientData = clientData } diff --git a/BankingPersistence/src/commonMain/sqldelight/net/codinux/banking/persistence/Bank.sq b/BankingPersistence/src/commonMain/sqldelight/net/codinux/banking/persistence/Bank.sq index 1c22fa1..d5c4a55 100644 --- a/BankingPersistence/src/commonMain/sqldelight/net/codinux/banking/persistence/Bank.sq +++ b/BankingPersistence/src/commonMain/sqldelight/net/codinux/banking/persistence/Bank.sq @@ -95,6 +95,12 @@ SET userSetDisplayName = ? WHERE id = ?; +updateBankClientData: +UPDATE BankAccess +SET clientData = ? +WHERE id = ?; + + deleteBank { DELETE FROM TanMethod WHERE bankId = :bankId; 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 9186580..9e53c12 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 @@ -281,6 +281,8 @@ class BankingService( bankingRepository.updateAccount(account, response.balance ?: account.balance, response.transactionsRetrievalTime, response.retrievedTransactionsFrom ?: account.retrievedTransactionsFrom) } + bankingRepository.updateBank(bank, bank.clientData) + notifyBanksListUpdated() // notify about updated values like account balance } catch (e: Throwable) { log.error(e) { "Could not save updated account transactions for bank $bank" }