Saving clientData in db
This commit is contained in:
parent
e0e150e53a
commit
04fa2dcbb4
|
@ -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?)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -95,6 +95,12 @@ SET userSetDisplayName = ?
|
|||
WHERE id = ?;
|
||||
|
||||
|
||||
updateBankClientData:
|
||||
UPDATE BankAccess
|
||||
SET clientData = ?
|
||||
WHERE id = ?;
|
||||
|
||||
|
||||
deleteBank {
|
||||
DELETE FROM TanMethod
|
||||
WHERE bankId = :bankId;
|
||||
|
|
|
@ -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" }
|
||||
|
|
Loading…
Reference in New Issue