Implemented saveing updated account properties in db after retrieving transactions
This commit is contained in:
parent
20fdc8dece
commit
e4a8a79ee3
|
@ -1,6 +1,9 @@
|
|||
package net.codinux.banking.persistence
|
||||
|
||||
import kotlinx.datetime.Instant
|
||||
import kotlinx.datetime.LocalDate
|
||||
import net.codinux.banking.client.model.AccountTransaction
|
||||
import net.codinux.banking.client.model.Amount
|
||||
import net.codinux.banking.client.model.BankAccess
|
||||
import net.codinux.banking.client.model.securitiesaccount.Holding
|
||||
import net.codinux.banking.persistence.entities.AccountTransactionEntity
|
||||
|
@ -30,6 +33,8 @@ interface BankingRepository {
|
|||
|
||||
suspend fun updateAccount(bank: BankAccountEntity, userSetDisplayName: String?, hideAccount: Boolean, includeInAutomaticAccountsUpdate: Boolean)
|
||||
|
||||
suspend fun updateAccount(account: BankAccountEntity, balance: Amount?, lastAccountUpdateTime: Instant, retrievedTransactionsFrom: LocalDate?)
|
||||
|
||||
suspend fun deleteBank(bank: BankAccessEntity)
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package net.codinux.banking.persistence
|
||||
|
||||
import kotlinx.datetime.Instant
|
||||
import kotlinx.datetime.LocalDate
|
||||
import net.codinux.banking.client.model.AccountTransaction
|
||||
import net.codinux.banking.client.model.Amount
|
||||
import net.codinux.banking.client.model.BankAccess
|
||||
import net.codinux.banking.client.model.securitiesaccount.Holding
|
||||
import net.codinux.banking.persistence.entities.AccountTransactionEntity
|
||||
|
@ -56,6 +59,10 @@ class InMemoryBankingRepository(
|
|||
// no-op
|
||||
}
|
||||
|
||||
override suspend fun updateAccount(account: BankAccountEntity, balance: Amount?, lastAccountUpdateTime: Instant, retrievedTransactionsFrom: LocalDate?) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
override suspend fun deleteBank(bank: BankAccessEntity) {
|
||||
this.banks.remove(bank)
|
||||
}
|
||||
|
|
|
@ -141,18 +141,32 @@ open class SqliteBankingRepository : BankingRepository {
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun updateAccount(bank: BankAccountEntity, userSetDisplayName: String?, hideAccount: Boolean, includeInAutomaticAccountsUpdate: Boolean) {
|
||||
override suspend fun updateAccount(account: BankAccountEntity, userSetDisplayName: String?, hideAccount: Boolean, includeInAutomaticAccountsUpdate: Boolean) {
|
||||
bankQueries.transaction {
|
||||
if (bank.userSetDisplayName != userSetDisplayName) {
|
||||
bankQueries.updateBankAccountUserSetDisplayName(userSetDisplayName, bank.id)
|
||||
if (account.userSetDisplayName != userSetDisplayName) {
|
||||
bankQueries.updateBankAccountUserSetDisplayName(userSetDisplayName, account.id)
|
||||
}
|
||||
|
||||
if (bank.hideAccount != hideAccount) {
|
||||
bankQueries.updateBankAccountHideAccount(hideAccount, bank.id)
|
||||
if (account.hideAccount != hideAccount) {
|
||||
bankQueries.updateBankAccountHideAccount(hideAccount, account.id)
|
||||
}
|
||||
|
||||
if (bank.includeInAutomaticAccountsUpdate != includeInAutomaticAccountsUpdate) {
|
||||
bankQueries.updateBankAccountIncludeInAutomaticAccountsUpdate(includeInAutomaticAccountsUpdate, bank.id)
|
||||
if (account.includeInAutomaticAccountsUpdate != includeInAutomaticAccountsUpdate) {
|
||||
bankQueries.updateBankAccountIncludeInAutomaticAccountsUpdate(includeInAutomaticAccountsUpdate, account.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -187,6 +187,22 @@ SELECT BankAccount.*
|
|||
FROM BankAccount;
|
||||
|
||||
|
||||
updateBankAccountBalance:
|
||||
UPDATE BankAccount
|
||||
SET balance = ?
|
||||
WHERE id = ?;
|
||||
|
||||
updateBankAccountLastAccountUpdateTime:
|
||||
UPDATE BankAccount
|
||||
SET lastAccountUpdateTime = ?
|
||||
WHERE id = ?;
|
||||
|
||||
updateBankAccountRetrievedTransactionsFrom:
|
||||
UPDATE BankAccount
|
||||
SET retrievedTransactionsFrom = ?
|
||||
WHERE id = ?;
|
||||
|
||||
|
||||
updateBankAccountUserSetDisplayName:
|
||||
UPDATE BankAccount
|
||||
SET userSetDisplayName = ?
|
||||
|
|
|
@ -275,7 +275,11 @@ class BankingService(
|
|||
|
||||
val transactionsViewModel = updateTransactionsInUi(newTransactionsEntities)
|
||||
uiState.dispatchNewTransactionsRetrieved(AccountTransactionsRetrievedEvent(bank, account, transactionsViewModel, response.holdings))
|
||||
|
||||
bankingRepository.updateAccount(account, response.balance, response.transactionsRetrievalTime, response.retrievedTransactionsFrom)
|
||||
}
|
||||
|
||||
notifyBanksListUpdated() // notify about updated values like account balance
|
||||
} catch (e: Throwable) {
|
||||
log.error(e) { "Could not save updated account transactions for bank $bank" }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue