diff --git a/PadelClub/Data/MonthData.swift b/PadelClub/Data/MonthData.swift index ab49252..78bed5a 100644 --- a/PadelClub/Data/MonthData.swift +++ b/PadelClub/Data/MonthData.swift @@ -10,44 +10,16 @@ import SwiftUI import LeStorage @Observable -final class MonthData: ModelObject, Storable { - - static func resourceName() -> String { return "month-data" } - static func tokenExemptedMethods() -> [HTTPMethod] { return [] } - static func filterByStoreIdentifier() -> Bool { return false } - static var relationshipNames: [String] = [] - - private(set) var id: String = Store.randomId() - private(set) var monthKey: String - private(set) var creationDate: Date - var maleUnrankedValue: Int? = nil - var femaleUnrankedValue: Int? = nil - var maleCount: Int? = nil - var femaleCount: Int? = nil - var anonymousCount: Int? = nil - var incompleteMode: Bool = false - var dataModelIdentifier: String? - var fileModelIdentifier: String? +final class MonthData: BaseMonthData { init(monthKey: String) { + super.init() self.monthKey = monthKey self.creationDate = Date() } required init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: ._id) - monthKey = try container.decode(String.self, forKey: ._monthKey) - creationDate = try container.decode(Date.self, forKey: ._creationDate) - maleUnrankedValue = try container.decodeIfPresent(Int.self, forKey: ._maleUnrankedValue) - femaleUnrankedValue = try container.decodeIfPresent(Int.self, forKey: ._femaleUnrankedValue) - maleCount = try container.decodeIfPresent(Int.self, forKey: ._maleCount) - femaleCount = try container.decodeIfPresent(Int.self, forKey: ._femaleCount) - anonymousCount = try container.decodeIfPresent(Int.self, forKey: ._anonymousCount) - incompleteMode = try container.decodeIfPresent(Bool.self, forKey: ._incompleteMode) ?? false - dataModelIdentifier = try container.decodeIfPresent(String.self, forKey: ._dataModelIdentifier) ?? nil - fileModelIdentifier = try container.decodeIfPresent(String.self, forKey: ._fileModelIdentifier) ?? nil - + try super.init(from: decoder) } func total() -> Int { @@ -77,33 +49,9 @@ final class MonthData: ModelObject, Storable { currentMonthData.femaleUnrankedValue = lastDataSourceFemaleUnranked?.0 currentMonthData.femaleCount = lastDataSourceFemaleUnranked?.1 currentMonthData.anonymousCount = anonymousCount - do { - try DataStore.shared.monthData.addOrUpdate(instance: currentMonthData) - } catch { - Logger.error(error) - } + DataStore.shared.monthData.addOrUpdate(instance: currentMonthData) + } } - - override func deleteDependencies() { - } - -// enum CodingKeys: String, CodingKey { -// case _id = "id" -// case _monthKey = "monthKey" -// case _creationDate = "creationDate" -// case _maleUnrankedValue = "maleUnrankedValue" -// case _femaleUnrankedValue = "femaleUnrankedValue" -// case _maleCount = "maleCount" -// case _femaleCount = "femaleCount" -// case _anonymousCount = "anonymousCount" -// case _incompleteMode = "incompleteMode" -// case _dataModelIdentifier = "dataModelIdentifier" -// case _fileModelIdentifier = "fileModelIdentifier" -// } - - func copy(from other: any Storable) { - fatalError("should not happen") - } }