30 lines
768 B
Swift
30 lines
768 B
Swift
import Foundation
|
|
|
|
protocol VehicleServiceProtocol {
|
|
|
|
func check(plateNumber: String, force: Bool) async throws -> CDVehicle
|
|
}
|
|
|
|
class VehicleService: VehicleServiceProtocol {
|
|
|
|
private let api: ApiProtocol
|
|
private let storage: StorageServiceProtocol
|
|
|
|
static let shared = VehicleService()
|
|
|
|
init(api: ApiProtocol = Api.shared, storage: StorageServiceProtocol = StorageService.shared) {
|
|
|
|
self.api = api
|
|
self.storage = storage
|
|
}
|
|
|
|
// MARK: - VehicleServiceProtocol
|
|
|
|
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)
|
|
}
|
|
|
|
}
|