All fuel prices per station (E10/E5/Diesel from one fetch); re-fetch on fuel switch; fuel tabs populate instantly
This commit is contained in:
@@ -56,7 +56,7 @@ struct RelayFuelProvider: FuelPriceProviding {
|
||||
postcode: relay.postcode ?? "",
|
||||
lat: relay.lat ?? 0,
|
||||
lng: relay.lng ?? 0,
|
||||
prices: [fuel: relay.price],
|
||||
prices: relay.allPrices,
|
||||
priceUpdated: nil
|
||||
)
|
||||
}
|
||||
@@ -72,7 +72,29 @@ private struct RelayResponse: Codable {
|
||||
let postcode: String?
|
||||
let lat: Double?
|
||||
let lng: Double?
|
||||
let price: Double
|
||||
let price: Double?
|
||||
let prices: [String: Double]?
|
||||
|
||||
/// Map relay grade keys (E5/E10/DIESEL) to FuelType for ALL fuels the
|
||||
/// station sells — one fetch populates every fuel tab.
|
||||
var allPrices: [FuelType: Double] {
|
||||
var result: [FuelType: Double] = [:]
|
||||
if let prices {
|
||||
for (grade, value) in prices {
|
||||
switch grade.uppercased() {
|
||||
case "E10": result[.e10] = value
|
||||
case "E5": result[.e5] = value
|
||||
case "DIESEL", "B7", "B7S", "B7P", "B10": result[.diesel] = value
|
||||
default: break
|
||||
}
|
||||
}
|
||||
}
|
||||
// Backwards-compat: relay versions without `prices` still send `price`.
|
||||
if result.isEmpty, let price {
|
||||
result[.e10] = price
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
let stations: [RelayStation]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user