Implemented saving only unpersisted transactions, not whole account
This commit is contained in:
parent
7dd1cd01b2
commit
3f093889a0
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue