Payments
This commit is contained in:
80
pedi-foods/Sources/PediFoods/Services/ApiPizzaModels.swift
Normal file
80
pedi-foods/Sources/PediFoods/Services/ApiPizzaModels.swift
Normal file
@@ -0,0 +1,80 @@
|
||||
import Foundation
|
||||
|
||||
struct StorePizzaConfig: Decodable {
|
||||
let sizes: [StorePizzaSize]
|
||||
let doughs: [StorePizzaDough]
|
||||
let crusts: [StorePizzaCrust]
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case sizes
|
||||
case doughs
|
||||
case crusts
|
||||
}
|
||||
|
||||
init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
sizes = (try? container.decode([StorePizzaSize].self, forKey: .sizes)) ?? []
|
||||
doughs = (try? container.decode([StorePizzaDough].self, forKey: .doughs)) ?? []
|
||||
crusts = (try? container.decode([StorePizzaCrust].self, forKey: .crusts)) ?? []
|
||||
}
|
||||
}
|
||||
|
||||
struct StorePizzaSize: Decodable, Identifiable {
|
||||
let id: String
|
||||
let name: String?
|
||||
let slices: Int?
|
||||
let maxFlavors: Int?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case id
|
||||
case name
|
||||
case slices
|
||||
case maxFlavors
|
||||
}
|
||||
}
|
||||
|
||||
struct StorePizzaDough: Decodable, Identifiable {
|
||||
let id: String
|
||||
let name: String?
|
||||
let active: Bool?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case id
|
||||
case name
|
||||
case active
|
||||
}
|
||||
}
|
||||
|
||||
struct StorePizzaCrust: Decodable, Identifiable {
|
||||
let id: String
|
||||
let name: String?
|
||||
let active: Bool?
|
||||
let priceModifier: Double?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case id
|
||||
case name
|
||||
case active
|
||||
case priceModifier
|
||||
}
|
||||
|
||||
init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
id = (try? container.decode(String.self, forKey: .id)) ?? UUID().uuidString
|
||||
name = try? container.decode(String.self, forKey: .name)
|
||||
active = try? container.decode(Bool.self, forKey: .active)
|
||||
|
||||
if let value = try? container.decode(Double.self, forKey: .priceModifier) {
|
||||
priceModifier = value
|
||||
} else if let value = try? container.decode(Int.self, forKey: .priceModifier) {
|
||||
priceModifier = Double(value)
|
||||
} else if let value = try? container.decode(String.self, forKey: .priceModifier) {
|
||||
let normalized = value
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
.replacingOccurrences(of: ",", with: ".")
|
||||
priceModifier = Double(normalized)
|
||||
} else {
|
||||
priceModifier = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user