Add lead workflows, PDF signing, AR projects and photo gallery integration
This commit is contained in:
27
GasTankAR/Data/Leads/LeadARPhotoStore.swift
Normal file
27
GasTankAR/Data/Leads/LeadARPhotoStore.swift
Normal file
@ -0,0 +1,27 @@
|
||||
import Foundation
|
||||
import SwiftData
|
||||
|
||||
/// Reads project photos through the lead association in a fresh context after AR closes.
|
||||
@MainActor
|
||||
final class LeadARPhotoStore {
|
||||
private let context: ModelContext
|
||||
|
||||
init(container: ModelContainer) {
|
||||
context = ModelContext(container)
|
||||
context.autosaveEnabled = false
|
||||
}
|
||||
|
||||
func photos(for leadID: String) throws -> [ProjectPhoto] {
|
||||
let links = try context.fetch(FetchDescriptor<LeadARProjectLink>(
|
||||
predicate: #Predicate { $0.leadID == leadID }))
|
||||
let legacy = try context.fetch(FetchDescriptor<Project>(
|
||||
predicate: #Predicate { $0.leadID == leadID }))
|
||||
var projects = links.compactMap(\.project)
|
||||
let linkedIDs = Set(projects.map(\.projectID))
|
||||
projects.append(contentsOf: legacy.filter { !linkedIDs.contains($0.projectID) })
|
||||
var seen = Set<PersistentIdentifier>()
|
||||
return projects.flatMap(\.photos)
|
||||
.filter { seen.insert($0.persistentModelID).inserted }
|
||||
.sorted { $0.creationDate > $1.creationDate }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user