AutoCat2/AutoCatCore/Services/VehicleService.swift
2022-03-25 19:51:57 +03:00

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)
}
}