05/02 Phase C

This commit is contained in:
Nguyen Ngo
2026-05-03 08:31:25 -04:00
parent 8bdcbecd73
commit 59e698b5f7
6 changed files with 451 additions and 147 deletions
+31 -10
View File
@@ -40,11 +40,6 @@ struct APIUser: Decodable {
let email: String
let role: String
let createdAt: String?
// Computed display name: full name if present, otherwise username.
// The server's /auth/me endpoint returns username; display_name would
// require a separate field. For Phase A we use username as the display name
// and can extend later.
var displayName: String { username }
}
@@ -102,18 +97,44 @@ struct APITemplate: Decodable, Identifiable {
let name: String
let description: String
let frequency: String
let formSchema: [[String: AnyDecodable]] // Dynamic JSON fields
let formSchema: [[String: AnyDecodable]]
}
// Inspections (Phase C history)
struct InspectionHistoryResponseData: Decodable {
let inspections: [APIInspectionSummary]
let total: Int
let limit: Int
let offset: Int
}
struct APIInspectionSummary: Decodable, Identifiable {
let id: Int
let templateId: Int
let templateName: String
let facilityId: Int
let facilityName: String
let areaId: Int?
let areaName: String?
let status: String
let overallScore: Double?
let inspectionDate: String?
let completedAt: String?
let mobileLocalId: String?
var inspectionDateParsed: Date? {
guard let str = inspectionDate else { return nil }
return ISO8601DateFormatter().date(from: str)
}
}
// AnyDecodable helper
// Allows decoding JSON values of unknown type (String, Int, Bool, Array, Dict)
struct AnyDecodable: Decodable {
let value: Any
init(_ value: Any) {
self.value = value
}
init(_ value: Any) { self.value = value }
init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()