Skip to content

Commit

Permalink
Fix Attendee & Scenario decode error
Browse files Browse the repository at this point in the history
  • Loading branch information
viere1234 committed Aug 24, 2023
1 parent ac98afd commit 636f014
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion OPassData/General/DateInRegionTransform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ struct StringToDate: TransformFunction {

struct IntToDate: TransformFunction {
static func transform(_ time: Int) -> DateInRegion {
return DateInRegion(seconds: TimeInterval(time), region: Region.current)
return DateInRegion(seconds: .init(time), region: .current)
}
}
2 changes: 1 addition & 1 deletion OPassData/Model/Attendee.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct Attendee: Hashable, Codable, Identifiable {
@Transform<Scenario> var scenarios: OrderedDictionary<String, [Scenario]>

private enum CodingKeys: String, CodingKey {
case id
case id = "_id"
case eventId = "event_id"
case userId = "user_id"
case token
Expand Down
17 changes: 17 additions & 0 deletions OPassData/Model/Scenario.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ struct Scenario: Hashable, Codable, Identifiable {
case attributes = "attr"
case used
}

init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decode(String.self, forKey: .id)
self.order = try container.decode(Int.self, forKey: .order)
self.title = try container.decode(LocalizedCodeString.self, forKey: .title)
self.disabled = try container.decodeIfPresent(String.self, forKey: .disabled)
self._available = try container.decode(Transform<IntToDate>.self, forKey: .available)
self._expire = try container.decode(Transform<IntToDate>.self, forKey: .expire)
self.countdown = try container.decode(Int.self, forKey: .countdown)
self.attributes = try container.decode([String : String].self, forKey: .attributes)
if let used = try? container.decode(Int.self, forKey: .used) {
self.used = .init(seconds: .init(used), region: .current)
} else if let used = try? container.decode(DateInRegion.self, forKey: .used) {
self.used = used
} else { self.used = nil }
}
}

extension Scenario {
Expand Down

0 comments on commit 636f014

Please sign in to comment.