Jul 13 - Update codes to catch up with the web app updates: scheduled inspection and issue's handler

This commit is contained in:
Nguyen Ngo
2026-07-13 14:03:41 -04:00
parent c05f0029fb
commit 20f9a99646
22 changed files with 5800 additions and 18 deletions
@@ -0,0 +1,47 @@
// Models/LocalScheduledInspection.swift
// --------------------------------------
// SwiftData model for planned/recurring inspection assignments (phase36).
//
// Read-only reference data pulled from the server (GET /api/v1/scheduled-inspections)
// and refreshed by SyncManager.pullScheduledInspections() never created or
// mutated on device. Surfaced in the "Scheduled" section on the Dashboard and
// My Inspections. Tapping "Start" opens the normal new-inspection flow with the
// facility + template preselected; the schedule lifecycle (fulfil / roll-forward)
// stays server-driven.
//
// All non-optional stored properties carry explicit inline defaults so SwiftData
// lightweight migration can add the new table without a migration plan.
import Foundation
import SwiftData
@Model
final class LocalScheduledInspection {
/// Server ID of the ScheduledInspection row stable unique identity.
@Attribute(.unique) var serverId: Int = 0
var facilityServerId: Int = 0
var facilityName: String = ""
var templateServerId: Int = 0
var templateName: String = ""
var inspectorId: Int? = nil
var frequency: String = "once" // once | daily | weekly | monthly
var frequencyLabel: String = "" // human-readable label from server
/// Raw ISO date string "YYYY-MM-DD" from the server (display fallback).
var dueDateString: String = ""
/// Parsed due date used for @Query sorting. Nil if the string was absent.
var nextDue: Date? = nil
var isOverdue: Bool = false
var notes: String? = nil
/// Last time this row was refreshed from the server pull.
var updatedAt: Date = Date()
init(serverId: Int) {
self.serverId = serverId
}
}