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 1ad58a8..f6b3665 100644 --- a/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/BankingRepository.kt +++ b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/BankingRepository.kt @@ -31,9 +31,9 @@ interface BankingRepository { suspend fun updateBank(bank: BankAccessEntity, loginName: String, password: String, bankName: String?) - suspend fun updateAccount(bank: BankAccountEntity, userSetDisplayName: String?, hideAccount: Boolean, includeInAutomaticAccountsUpdate: Boolean) + suspend fun updateAccount(account: BankAccountEntity, userSetDisplayName: String?, hideAccount: Boolean, includeInAutomaticAccountsUpdate: Boolean) - suspend fun updateAccount(account: BankAccountEntity, balance: Amount?, lastAccountUpdateTime: Instant, retrievedTransactionsFrom: LocalDate?) + suspend fun updateAccount(account: BankAccountEntity, balance: Amount, lastAccountUpdateTime: Instant, retrievedTransactionsFrom: LocalDate?) suspend fun deleteBank(bank: BankAccessEntity) 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 3519f2d..1e1aeb5 100644 --- a/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/InMemoryBankingRepository.kt +++ b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/InMemoryBankingRepository.kt @@ -55,11 +55,11 @@ class InMemoryBankingRepository( // no-op } - override suspend fun updateAccount(bank: BankAccountEntity, userSetDisplayName: String?, hideAccount: Boolean, includeInAutomaticAccountsUpdate: Boolean) { + override suspend fun updateAccount(account: BankAccountEntity, userSetDisplayName: String?, hideAccount: Boolean, includeInAutomaticAccountsUpdate: Boolean) { // no-op } - override suspend fun updateAccount(account: BankAccountEntity, balance: Amount?, lastAccountUpdateTime: Instant, retrievedTransactionsFrom: LocalDate?) { + override suspend fun updateAccount(account: BankAccountEntity, balance: Amount, lastAccountUpdateTime: Instant, retrievedTransactionsFrom: LocalDate?) { // 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 9edb01a..e730e84 100644 --- a/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/SqliteBankingRepository.kt +++ b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/SqliteBankingRepository.kt @@ -157,18 +157,8 @@ open class SqliteBankingRepository : BankingRepository { } } - override suspend fun updateAccount(account: BankAccountEntity, balance: Amount?, lastAccountUpdateTime: Instant, retrievedTransactionsFrom: LocalDate?) { - bankQueries.transaction { - if (balance != null && account.balance != balance) { - bankQueries.updateBankAccountBalance(mapAmount(balance), account.id) - } - - bankQueries.updateBankAccountLastAccountUpdateTime(mapInstant(lastAccountUpdateTime), account.id) - - if (retrievedTransactionsFrom != null && (account.retrievedTransactionsFrom == null || account.retrievedTransactionsFrom!! > retrievedTransactionsFrom)) { - bankQueries.updateBankAccountRetrievedTransactionsFrom(mapDate(retrievedTransactionsFrom), account.id) - } - } + override suspend fun updateAccount(account: BankAccountEntity, balance: Amount, lastAccountUpdateTime: Instant, retrievedTransactionsFrom: LocalDate?) { + bankQueries.updateBankAccount(mapAmount(balance), mapInstant(lastAccountUpdateTime), mapDate(retrievedTransactionsFrom), account.id) } override suspend fun deleteBank(bank: BankAccessEntity) { 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 f99c1ec..1c22fa1 100644 --- a/BankingPersistence/src/commonMain/sqldelight/net/codinux/banking/persistence/Bank.sq +++ b/BankingPersistence/src/commonMain/sqldelight/net/codinux/banking/persistence/Bank.sq @@ -187,20 +187,10 @@ SELECT BankAccount.* FROM BankAccount; -updateBankAccountBalance: +updateBankAccount: UPDATE BankAccount -SET balance = ? -WHERE id = ?; - -updateBankAccountLastAccountUpdateTime: -UPDATE BankAccount -SET lastAccountUpdateTime = ? -WHERE id = ?; - -updateBankAccountRetrievedTransactionsFrom: -UPDATE BankAccount -SET retrievedTransactionsFrom = ? -WHERE id = ?; +SET balance = :balance, lastAccountUpdateTime = :lastAccountUpdateTime, retrievedTransactionsFrom = :retrievedTransactionsFrom +WHERE id = :accountId; updateBankAccountUserSetDisplayName: 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 3c178bb..c33211d 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 @@ -276,7 +276,7 @@ class BankingService( val transactionsViewModel = updateTransactionsInUi(newTransactionsEntities) uiState.dispatchNewTransactionsRetrieved(AccountTransactionsRetrievedEvent(bank, account, transactionsViewModel, response.holdings)) - bankingRepository.updateAccount(account, response.balance, response.transactionsRetrievalTime, response.retrievedTransactionsFrom) + bankingRepository.updateAccount(account, response.balance ?: account.balance, response.transactionsRetrievalTime, response.retrievedTransactionsFrom ?: account.retrievedTransactionsFrom) } notifyBanksListUpdated() // notify about updated values like account balance