36 lines
971 B
Swift
36 lines
971 B
Swift
import Foundation
|
|
|
|
protocol VehicleServiceProtocol {
|
|
|
|
func check(plateNumber: String, force: Bool) async throws -> CDVehicle
|
|
}
|
|
|
|
public class VehicleService: VehicleServiceProtocol {
|
|
|
|
private let api: ApiProtocol
|
|
private let storage: StorageServiceProtocol
|
|
|
|
public static var shared: VehicleService {
|
|
get async throws {
|
|
let storageService = try await StorageService.shared
|
|
return VehicleService(api: Api.shared, storage: storageService)
|
|
}
|
|
}
|
|
|
|
init(api: ApiProtocol = Api.shared, storage: StorageServiceProtocol) {
|
|
|
|
self.api = api
|
|
self.storage = storage
|
|
}
|
|
|
|
// MARK: - VehicleServiceProtocol
|
|
|
|
@discardableResult
|
|
public func check(plateNumber: String, force: Bool) async throws -> CDVehicle {
|
|
|
|
let vehicle = try await api.check(plateNumber: plateNumber, force: force)
|
|
return try storage.store(vehicle: vehicle)
|
|
}
|
|
|
|
}
|