Transform to multi-account support
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// MeteClientDrink.swift
|
||||
// meterios
|
||||
//
|
||||
// (c) 2025 Martin "maride" Dessauer
|
||||
//
|
||||
|
||||
/// **MeteClientDrink** resembles a drink retrieved from Space Market API, Version 1. Pure Swift, no platform-specific frameworks used.
|
||||
struct MeteClientDrink: Identifiable, Codable {
|
||||
let id: Int
|
||||
let name: String
|
||||
let logoURL: String
|
||||
let price: Float?
|
||||
let bottle_size: Float?
|
||||
let caffeine: Int?
|
||||
let active: Bool
|
||||
|
||||
// KeyMap is an enum covering the field names as used by SpaceMarket API
|
||||
private enum CodingKeys : String, CodingKey { case id, name, bottle_size, caffeine, price, active, logoURL = "logo_url" }
|
||||
|
||||
// Init function to be used with JSONDecoder using SpaceMarket API's strange types
|
||||
init(from decoder : Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
self.id = try container.decode(Int.self, forKey: .id)
|
||||
self.name = try container.decode(String.self, forKey: .name)
|
||||
self.bottle_size = Float((try? container.decode(String.self, forKey: .bottle_size)) ?? "")
|
||||
self.caffeine = (try? container.decode(Int.self, forKey: .caffeine))
|
||||
self.price = Float((try? container.decode(String.self, forKey: .price)) ?? "")
|
||||
self.active = (try? container.decode(Bool.self, forKey: .active)) ?? false
|
||||
self.logoURL = (try? container.decode(String.self, forKey: .logoURL)) ?? ""
|
||||
}
|
||||
|
||||
// Init function, as straight-forward as it gets
|
||||
init(id: Int, name: String, logoURL: String = "", price: Float = 0, bottle_size: Float = 0, caffeine: Int = 0, active: Bool = true) {
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.logoURL = logoURL
|
||||
self.price = price
|
||||
self.bottle_size = bottle_size
|
||||
self.caffeine = caffeine
|
||||
self.active = active
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user