From 8b1543b2dcda36e68e149918d1d1507e1a231f53 Mon Sep 17 00:00:00 2001 From: Ryan Priebe Date: Tue, 10 Jan 2023 10:41:53 -0700 Subject: [PATCH] this fixes bug #47 --- DLPrototype/Models/CoreData/LogRecords.swift | 22 ++++++++++++++++++++ DLPrototype/Views/Today/Today.swift | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/DLPrototype/Models/CoreData/LogRecords.swift b/DLPrototype/Models/CoreData/LogRecords.swift index eab3a634..224c09b5 100644 --- a/DLPrototype/Models/CoreData/LogRecords.swift +++ b/DLPrototype/Models/CoreData/LogRecords.swift @@ -55,6 +55,28 @@ class LogRecords: ObservableObject, Identifiable, Equatable { return (false, nil) } + public func jobMatch(_ job: Double) -> (Bool, Job?) { + var jobs: [Job] = [] + let fetch: NSFetchRequest = Job.fetchRequest() + fetch.sortDescriptors = [NSSortDescriptor(keyPath: \Job.jid, ascending: true)] + + do { + jobs = try moc!.fetch(fetch) + } catch { + print("Unable to find records for today") + + return (false, nil) + } + + for j in jobs { + if j.jid == job { + return (true, j) + } + } + + return (false, nil) + } + public func fromToday() -> Void { let fetch: NSFetchRequest = LogRecord.fetchRequest() fetch.sortDescriptors = [NSSortDescriptor(keyPath: \LogRecord.timestamp, ascending: true)] diff --git a/DLPrototype/Views/Today/Today.swift b/DLPrototype/Views/Today/Today.swift index fab84eab..f501ed60 100644 --- a/DLPrototype/Views/Today/Today.swift +++ b/DLPrototype/Views/Today/Today.swift @@ -180,7 +180,7 @@ struct Today : View, Identifiable { record.message = text record.id = UUID() - let (success, matchedJob) = recordsModel.jobMatchWithSet(jid, today) + let (success, matchedJob) = recordsModel.jobMatch(jid) if !success { let job = Job(context: moc)