Transform to multi-account support

This commit is contained in:
2025-08-01 19:31:53 +02:00
parent 351f08e43e
commit 68239727fa
24 changed files with 635 additions and 503 deletions
+43
View File
@@ -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
}
}