use generated class

sync2
Laurent 1 year ago
parent d6bd8842c3
commit f1b351a13f
  1. 62
      PadelClub/Data/MonthData.swift

@ -10,44 +10,16 @@ import SwiftUI
import LeStorage import LeStorage
@Observable @Observable
final class MonthData: ModelObject, Storable { final class MonthData: BaseMonthData {
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?
init(monthKey: String) { init(monthKey: String) {
super.init()
self.monthKey = monthKey self.monthKey = monthKey
self.creationDate = Date() self.creationDate = Date()
} }
required init(from decoder: Decoder) throws { required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self) try super.init(from: decoder)
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
} }
func total() -> Int { func total() -> Int {
@ -77,33 +49,9 @@ final class MonthData: ModelObject, Storable {
currentMonthData.femaleUnrankedValue = lastDataSourceFemaleUnranked?.0 currentMonthData.femaleUnrankedValue = lastDataSourceFemaleUnranked?.0
currentMonthData.femaleCount = lastDataSourceFemaleUnranked?.1 currentMonthData.femaleCount = lastDataSourceFemaleUnranked?.1
currentMonthData.anonymousCount = anonymousCount currentMonthData.anonymousCount = anonymousCount
do { DataStore.shared.monthData.addOrUpdate(instance: currentMonthData)
try DataStore.shared.monthData.addOrUpdate(instance: currentMonthData)
} catch {
Logger.error(error)
}
}
}
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")
} }
} }

Loading…
Cancel
Save