From 1c7fa49de58366ea56d5079b14184e6f6203fe83 Mon Sep 17 00:00:00 2001 From: dankito Date: Tue, 15 Oct 2024 19:48:56 +0200 Subject: [PATCH] Updated to new data model that their is now BankAccess.clientData and serializedClientData --- .../codinux/banking/persistence/BankingRepository.kt | 2 +- .../banking/persistence/InMemoryBankingRepository.kt | 2 +- .../banking/persistence/SqliteBankingRepository.kt | 12 ++++++------ .../banking/persistence/entities/BankAccessEntity.kt | 4 +++- .../net/codinux/banking/ui/service/BankingService.kt | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) 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 ad6dd0b..86fa639 100644 --- a/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/BankingRepository.kt +++ b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/BankingRepository.kt @@ -31,7 +31,7 @@ interface BankingRepository { suspend fun updateBank(bank: BankAccessEntity, loginName: String, password: String, bankName: String?) - suspend fun updateBank(bank: BankAccessEntity, clientData: String?) + suspend fun updateBank(bank: BankAccessEntity, serializedClientData: String?) suspend fun updateAccount(account: BankAccountEntity, userSetDisplayName: String?, hideAccount: Boolean, includeInAutomaticAccountsUpdate: Boolean) 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 97a835a..123b12f 100644 --- a/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/InMemoryBankingRepository.kt +++ b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/InMemoryBankingRepository.kt @@ -55,7 +55,7 @@ class InMemoryBankingRepository( // no-op } - override suspend fun updateBank(bank: BankAccessEntity, clientData: String?) { + override suspend fun updateBank(bank: BankAccessEntity, serializedClientData: String?) { // 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 3b60d58..37a631f 100644 --- a/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/SqliteBankingRepository.kt +++ b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/SqliteBankingRepository.kt @@ -95,9 +95,9 @@ open class SqliteBankingRepository : BankingRepository { val tanMedia = getAllTanMedia().groupBy { it.bankId }.mapValues { it.value.toMutableList() } val holdings = getAllHoldings().groupBy { it.accountId } - return bankQueries.getAllBanks { id, domesticBankCode, loginName, password, bankName, bic, customerName, userId, selectedTanMethodIdentifier, selectedTanMediumIdentifier, bankingGroup, serverAddress, countryCode, clientData, userSetDisplayName, displayIndex, iconUrl, wrongCredentialsEntered -> + return bankQueries.getAllBanks { id, domesticBankCode, loginName, password, bankName, bic, customerName, userId, selectedTanMethodIdentifier, selectedTanMediumIdentifier, bankingGroup, serverAddress, countryCode, serializedClientData, 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, clientData) + bankingGroup?.let { BankingGroup.valueOf(it) }, serverAddress, countryCode, userSetDisplayName, displayIndex.toInt(), iconUrl, wrongCredentialsEntered, null, serializedClientData) }.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, bank.clientData, bank.userSetDisplayName, bank.displayIndex.toLong(), bank.iconUrl, bank.wrongCredentialsEntered + bank.bankingGroup?.name, bank.serverAddress, bank.countryCode, bank.serializedClientData, 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,10 +141,10 @@ open class SqliteBankingRepository : BankingRepository { } } - override suspend fun updateBank(bank: BankAccessEntity, clientData: String?) { + override suspend fun updateBank(bank: BankAccessEntity, serializedClientData: String?) { bankQueries.transaction { - if (clientData != null) { - bankQueries.updateBankClientData(clientData, bank.id) + if (serializedClientData != null) { + bankQueries.updateBankClientData(serializedClientData, bank.id) } } } 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 718a931..c19f776 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 @@ -34,7 +34,8 @@ class BankAccessEntity( iconUrl: String? = null, wrongCredentialsEntered: Boolean = false, - clientData: String? = null + clientData: Any? = null, + serializedClientData: String? = null ) : BankAccess(domesticBankCode, loginName, password, bankName, bic, customerName, userId, accounts, selectedTanMethodIdentifier, tanMethods, selectedTanMediumIdentifier, tanMedia, bankingGroup, serverAddress, countryCode) { init { @@ -45,6 +46,7 @@ class BankAccessEntity( this.wrongCredentialsEntered = wrongCredentialsEntered this.clientData = clientData + this.serializedClientData = serializedClientData } 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 a443522..8a7f1a6 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 @@ -291,7 +291,7 @@ class BankingService( bankingRepository.updateAccount(account, response.balance ?: account.balance, response.transactionsRetrievalTime, response.retrievedTransactionsFrom ?: account.retrievedTransactionsFrom) } - bankingRepository.updateBank(bank, bank.clientData) + bankingRepository.updateBank(bank, bank.serializedClientData) notifyBanksListUpdated() // notify about updated values like account balance } catch (e: Throwable) {