Implemented saving only unpersisted transactions, not whole account

This commit is contained in:
dankito 2020-09-01 15:13:11 +02:00
parent 7dd1cd01b2
commit 3f093889a0
1 changed files with 15 additions and 8 deletions

View File

@ -80,16 +80,23 @@ class CoreDataBankingPersistence: IBankingPersistence, IRemitteeSearcher {
} }
func saveOrUpdateAccountTransactions(bankAccount: BankAccount, transactions: [AccountTransaction]) { func saveOrUpdateAccountTransactions(bankAccount: BankAccount, transactions: [AccountTransaction]) {
if let persistedAccount = context.objectByID(bankAccount.technicalId) as? PersistedBankAccount {
for transaction in transactions {
if transaction.technicalId.isCoreDataId == false { // TODO: or also update already persisted transactions?
do { do {
let mapped = mapper.map(bankAccount.customer, context) let mappedTransaction = mapper.map(persistedAccount, transaction, context)
context.insert(mapped)
try context.save() try context.save()
transaction.technicalId = mappedTransaction.objectIDAsString
} catch { } catch {
NSLog("Could not save transactions of account \(bankAccount): \(error)") NSLog("Could not save transaction \(transaction.transactionIdentifier) of account \(bankAccount.displayName): \(error)")
} }
} }
}
}
}
func saveUrlToFile(url: String, file: URL) { func saveUrlToFile(url: String, file: URL) {
if let remoteUrl = URL.encoded(url) { if let remoteUrl = URL.encoded(url) {