Cleared Library import. Series encoding in Game was not necessary. Encoding through GameSeries object is enough
This commit is contained in:
@@ -51,14 +51,13 @@ extension Game : Encodable {
|
|||||||
case isFinished
|
case isFinished
|
||||||
case inWishlist
|
case inWishlist
|
||||||
case console
|
case console
|
||||||
case series
|
|
||||||
case cover_icloud_path
|
case cover_icloud_path
|
||||||
case pickupDescription
|
case pickupDescription
|
||||||
}
|
}
|
||||||
|
|
||||||
public func encode(to encoder: Encoder) throws {
|
public func encode(to encoder: Encoder) throws {
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
print("UUID: \(self.uuid)")
|
|
||||||
try container.encode(uuid, forKey: .uuid)
|
try container.encode(uuid, forKey: .uuid)
|
||||||
try container.encode(name, forKey: .name)
|
try container.encode(name, forKey: .name)
|
||||||
try container.encode(notes ?? "", forKey: .notes)
|
try container.encode(notes ?? "", forKey: .notes)
|
||||||
@@ -72,8 +71,6 @@ extension Game : Encodable {
|
|||||||
try container.encode(cover_icloud_path ?? "", forKey: .cover_icloud_path)
|
try container.encode(cover_icloud_path ?? "", forKey: .cover_icloud_path)
|
||||||
|
|
||||||
let consoleUUID : String = console?.uuid.uuidString ?? ""
|
let consoleUUID : String = console?.uuid.uuidString ?? ""
|
||||||
let gameSeriesUUID : String = series?.uuid.uuidString ?? ""
|
|
||||||
try container.encode(consoleUUID, forKey: .console)
|
try container.encode(consoleUUID, forKey: .console)
|
||||||
try container.encode(gameSeriesUUID, forKey: .series)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -201,46 +201,8 @@ struct BHLGame : Decodable {
|
|||||||
let createdAt : String
|
let createdAt : String
|
||||||
let pickupDescription : String?
|
let pickupDescription : String?
|
||||||
let publisher : String?
|
let publisher : String?
|
||||||
let console : UUID?
|
let console : UUID
|
||||||
let series : UUID?
|
|
||||||
let cover_icloud_path : String?
|
let cover_icloud_path : String?
|
||||||
|
|
||||||
enum CodingKeys: String, CodingKey {
|
|
||||||
case uuid
|
|
||||||
case name
|
|
||||||
case lentTo
|
|
||||||
case isDigital
|
|
||||||
case inWishlist
|
|
||||||
case isFinished
|
|
||||||
case notes
|
|
||||||
case createdAt
|
|
||||||
case pickupDescription
|
|
||||||
case publisher
|
|
||||||
case console
|
|
||||||
case series
|
|
||||||
case cover_icloud_path
|
|
||||||
}
|
|
||||||
|
|
||||||
init(from decoder: Decoder) throws {
|
|
||||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
||||||
uuid = try container.decode(UUID.self, forKey: .uuid)
|
|
||||||
name = try container.decode(String.self, forKey: .name)
|
|
||||||
lentTo = try container.decode(String?.self, forKey: .lentTo)
|
|
||||||
isDigital = try container.decode(Bool.self, forKey: .isDigital)
|
|
||||||
inWishlist = try container.decode(Bool.self, forKey: .inWishlist)
|
|
||||||
isFinished = try container.decode(Bool.self, forKey: .isFinished)
|
|
||||||
notes = try container.decode(String?.self, forKey: .notes)
|
|
||||||
createdAt = try container.decode(String.self, forKey: .createdAt)
|
|
||||||
pickupDescription = try container.decode(String?.self, forKey: .pickupDescription)
|
|
||||||
publisher = try container.decode(String?.self, forKey: .publisher)
|
|
||||||
cover_icloud_path = try container.decode(String?.self, forKey: .cover_icloud_path)
|
|
||||||
console = try container.decode(UUID?.self, forKey: .console)
|
|
||||||
do {
|
|
||||||
series = try container.decode(UUID?.self, forKey: .series)
|
|
||||||
}catch {
|
|
||||||
series = .none
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BHLAccessory : Decodable {
|
struct BHLAccessory : Decodable {
|
||||||
@@ -258,22 +220,6 @@ struct BHLGameSeries : Decodable {
|
|||||||
let name : String
|
let name : String
|
||||||
let games : [UUID]
|
let games : [UUID]
|
||||||
let cover_icloud_path : String?
|
let cover_icloud_path : String?
|
||||||
|
|
||||||
enum CodingKeys: String, CodingKey {
|
|
||||||
case uuid
|
|
||||||
case name
|
|
||||||
case cover
|
|
||||||
case games
|
|
||||||
case cover_icloud_path
|
|
||||||
}
|
|
||||||
|
|
||||||
init(from decoder: Decoder) throws {
|
|
||||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
||||||
uuid = try container.decode(UUID.self, forKey: .uuid)
|
|
||||||
name = try container.decode(String.self, forKey: .name)
|
|
||||||
cover_icloud_path = try container.decode(String.self, forKey: .cover_icloud_path)
|
|
||||||
games = try container.decode([UUID].self, forKey: .games)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BHLConsole : Decodable {
|
struct BHLConsole : Decodable {
|
||||||
@@ -285,27 +231,4 @@ struct BHLConsole : Decodable {
|
|||||||
let shortName : String?
|
let shortName : String?
|
||||||
let accessories : [UUID]
|
let accessories : [UUID]
|
||||||
let games : [UUID]
|
let games : [UUID]
|
||||||
|
|
||||||
enum CodingKeys: String, CodingKey {
|
|
||||||
case uuid
|
|
||||||
case name
|
|
||||||
case logo_icloud_path
|
|
||||||
case manufacturer
|
|
||||||
case releaseDate
|
|
||||||
case shortName
|
|
||||||
case accessories
|
|
||||||
case games
|
|
||||||
}
|
|
||||||
|
|
||||||
init(from decoder: Decoder) throws {
|
|
||||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
||||||
uuid = try container.decode(UUID.self, forKey: .uuid)
|
|
||||||
name = try container.decode(String.self, forKey: .name)
|
|
||||||
logo_icloud_path = try container.decode(String.self, forKey: .logo_icloud_path)
|
|
||||||
manufacturer = try container.decode(String?.self, forKey: .manufacturer)
|
|
||||||
shortName = try container.decode(String?.self, forKey: .shortName)
|
|
||||||
accessories = try container.decode([UUID].self, forKey: .accessories)
|
|
||||||
releaseDate = try container.decode(Date.self, forKey: .releaseDate)
|
|
||||||
games = try container.decode([UUID].self, forKey: .games)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user