AutoCat2/AutoCatCore/Services/VehicleService.swift

38 lines
986 B
Swift

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