feat: Begins adding climate zone client and location clients.

This commit is contained in:
2025-03-03 17:04:02 -05:00
parent 1727e9a905
commit 9da4149391
8 changed files with 158 additions and 1 deletions

View File

@@ -0,0 +1,74 @@
import Dependencies
import DependenciesMacros
import Foundation
public extension DependencyValues {
var locationClient: LocationClient {
get { self[LocationClient.self] }
set { self[LocationClient.self] = newValue }
}
}
@DependencyClient
public struct LocationClient: Sendable {
public var search: @Sendable (Int) async throws -> [Response]
// TODO: Add ClimateZone.ZoneIdentifier??
public struct Response: Codable, Equatable, Sendable {
public let city: String
public let latitude: String
public let longitude: String
public let zipCode: String
public let state: String
public let stateCode: String
public let county: String
public init(
city: String,
latitude: String,
longitude: String,
zipCode: String,
state: String,
stateCode: String,
county: String
) {
self.city = city
self.latitude = latitude
self.longitude = longitude
self.zipCode = zipCode
self.state = state
self.stateCode = stateCode
self.county = county
}
private enum CodingKeys: String, CodingKey {
case city
case latitude
case longitude
case zipCode = "postal_code"
case state
case stateCode = "state_code"
case county = "province"
}
}
}
extension LocationClient: TestDependencyKey {
public static let testValue: LocationClient = Self()
}
#if DEBUG
public extension LocationClient.Response {
static let mock = Self(
city: "Monroe",
latitude: "39.4413000",
longitude: "-84.3652000",
zipCode: "45050",
state: "Ohio",
stateCode: "OH",
county: "Butler"
)
}
#endif