Skip to content

Commit

Permalink
this fixes bug #47
Browse files Browse the repository at this point in the history
  • Loading branch information
aapis committed Jan 10, 2023
1 parent 7fd0a0a commit 8b1543b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions DLPrototype/Models/CoreData/LogRecords.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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> = 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> = LogRecord.fetchRequest()
fetch.sortDescriptors = [NSSortDescriptor(keyPath: \LogRecord.timestamp, ascending: true)]
Expand Down
2 changes: 1 addition & 1 deletion DLPrototype/Views/Today/Today.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8b1543b

Please sign in to comment.