Adding stubs for VehicleService

This commit is contained in:
Selim Mustafaev 2025-01-19 17:26:22 +03:00
parent bc88a7bb0e
commit 3cc2ef2101
7 changed files with 72 additions and 7 deletions

View File

@ -148,6 +148,8 @@
7AB4E42C2D397D8E0006D052 /* VehicleCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AB4E42B2D397D8E0006D052 /* VehicleCellView.swift */; }; 7AB4E42C2D397D8E0006D052 /* VehicleCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AB4E42B2D397D8E0006D052 /* VehicleCellView.swift */; };
7AB4E4332D3C21C00006D052 /* FileManagerExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AB4E4322D3C21C00006D052 /* FileManagerExt.swift */; }; 7AB4E4332D3C21C00006D052 /* FileManagerExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AB4E4322D3C21C00006D052 /* FileManagerExt.swift */; };
7AB4E4382D3D0C5C0006D052 /* VehiclesArchive.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AB4E4372D3D0C5C0006D052 /* VehiclesArchive.swift */; }; 7AB4E4382D3D0C5C0006D052 /* VehiclesArchive.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AB4E4372D3D0C5C0006D052 /* VehiclesArchive.swift */; };
7AB4E43B2D3D3F4F0006D052 /* VehicleServiceProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AB4E43A2D3D3F4F0006D052 /* VehicleServiceProtocol.swift */; };
7AB4E43D2D3D3F7A0006D052 /* VehicleService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AB4E43C2D3D3F7A0006D052 /* VehicleService.swift */; };
7AB5871D2C42C1CF00FA7B66 /* RealmSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 7AB5871C2C42C1CF00FA7B66 /* RealmSwift */; }; 7AB5871D2C42C1CF00FA7B66 /* RealmSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 7AB5871C2C42C1CF00FA7B66 /* RealmSwift */; };
7AB587322C42D38E00FA7B66 /* StorageServiceProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AB587312C42D38E00FA7B66 /* StorageServiceProtocol.swift */; }; 7AB587322C42D38E00FA7B66 /* StorageServiceProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AB587312C42D38E00FA7B66 /* StorageServiceProtocol.swift */; };
7AB587342C42D3FA00FA7B66 /* StorageService+Notes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AB587332C42D3FA00FA7B66 /* StorageService+Notes.swift */; }; 7AB587342C42D3FA00FA7B66 /* StorageService+Notes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AB587332C42D3FA00FA7B66 /* StorageService+Notes.swift */; };
@ -421,6 +423,8 @@
7AB4E42B2D397D8E0006D052 /* VehicleCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VehicleCellView.swift; sourceTree = "<group>"; }; 7AB4E42B2D397D8E0006D052 /* VehicleCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VehicleCellView.swift; sourceTree = "<group>"; };
7AB4E4322D3C21C00006D052 /* FileManagerExt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileManagerExt.swift; sourceTree = "<group>"; }; 7AB4E4322D3C21C00006D052 /* FileManagerExt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileManagerExt.swift; sourceTree = "<group>"; };
7AB4E4372D3D0C5C0006D052 /* VehiclesArchive.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VehiclesArchive.swift; sourceTree = "<group>"; }; 7AB4E4372D3D0C5C0006D052 /* VehiclesArchive.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VehiclesArchive.swift; sourceTree = "<group>"; };
7AB4E43A2D3D3F4F0006D052 /* VehicleServiceProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VehicleServiceProtocol.swift; sourceTree = "<group>"; };
7AB4E43C2D3D3F7A0006D052 /* VehicleService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VehicleService.swift; sourceTree = "<group>"; };
7AB562B9249C9E9B00473D53 /* VehicleRegion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VehicleRegion.swift; sourceTree = "<group>"; }; 7AB562B9249C9E9B00473D53 /* VehicleRegion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VehicleRegion.swift; sourceTree = "<group>"; };
7AB587222C42D27F00FA7B66 /* AutoCatTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AutoCatTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 7AB587222C42D27F00FA7B66 /* AutoCatTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AutoCatTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
7AB587312C42D38E00FA7B66 /* StorageServiceProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageServiceProtocol.swift; sourceTree = "<group>"; }; 7AB587312C42D38E00FA7B66 /* StorageServiceProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageServiceProtocol.swift; sourceTree = "<group>"; };
@ -765,6 +769,7 @@
7A45FB362C2706D000618694 /* Services */ = { 7A45FB362C2706D000618694 /* Services */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
7AB4E4392D3D3F390006D052 /* VehicleService */,
7A06E0B12C707DD7005731AC /* SettingsService */, 7A06E0B12C707DD7005731AC /* SettingsService */,
7A60D24B2C5A9D2700D13F7B /* LocationService */, 7A60D24B2C5A9D2700D13F7B /* LocationService */,
7AB5873D2C42FF4000FA7B66 /* ApiService */, 7AB5873D2C42FF4000FA7B66 /* ApiService */,
@ -952,6 +957,15 @@
path = ACImageSlider; path = ACImageSlider;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
7AB4E4392D3D3F390006D052 /* VehicleService */ = {
isa = PBXGroup;
children = (
7AB4E43A2D3D3F4F0006D052 /* VehicleServiceProtocol.swift */,
7AB4E43C2D3D3F7A0006D052 /* VehicleService.swift */,
);
path = VehicleService;
sourceTree = "<group>";
};
7AB587302C42D35900FA7B66 /* StorageService */ = { 7AB587302C42D35900FA7B66 /* StorageService */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@ -1450,6 +1464,7 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
7AB4E43D2D3D3F7A0006D052 /* VehicleService.swift in Sources */,
7A5D84C22C1AE5C900C2209B /* VehicleModel.swift in Sources */, 7A5D84C22C1AE5C900C2209B /* VehicleModel.swift in Sources */,
7A5D84B92C1AD3C200C2209B /* DtoConvertible.swift in Sources */, 7A5D84B92C1AD3C200C2209B /* DtoConvertible.swift in Sources */,
7AF6D2182677C1680086EA64 /* VehicleAd.swift in Sources */, 7AF6D2182677C1680086EA64 /* VehicleAd.swift in Sources */,
@ -1490,6 +1505,7 @@
7AB4E4332D3C21C00006D052 /* FileManagerExt.swift in Sources */, 7AB4E4332D3C21C00006D052 /* FileManagerExt.swift in Sources */,
7AB587322C42D38E00FA7B66 /* StorageServiceProtocol.swift in Sources */, 7AB587322C42D38E00FA7B66 /* StorageServiceProtocol.swift in Sources */,
7A3E12D72C7B42B700EE710D /* UserDefaults+Settings.swift in Sources */, 7A3E12D72C7B42B700EE710D /* UserDefaults+Settings.swift in Sources */,
7AB4E43B2D3D3F4F0006D052 /* VehicleServiceProtocol.swift in Sources */,
7AA514E02D0B75B3001CAC50 /* StorageService+Events.swift in Sources */, 7AA514E02D0B75B3001CAC50 /* StorageService+Events.swift in Sources */,
7A64A2222C19E99E00284124 /* DebugInfoDto.swift in Sources */, 7A64A2222C19E99E00284124 /* DebugInfoDto.swift in Sources */,
7A5D84BC2C1AD81000C2209B /* VehicleOwnershipPeriod.swift in Sources */, 7A5D84BC2C1AD81000C2209B /* VehicleOwnershipPeriod.swift in Sources */,

View File

@ -5,6 +5,7 @@ import AutoCatCore
class MainTabController: UITabBarController, UITabBarControllerDelegate { class MainTabController: UITabBarController, UITabBarControllerDelegate {
var settingsCoordinator: SettingsCoordinator? var settingsCoordinator: SettingsCoordinator?
var historyViewModel: HistoryViewModel?
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
@ -30,10 +31,11 @@ class MainTabController: UITabBarController, UITabBarControllerDelegate {
func setupHistoryTab() { func setupHistoryTab() {
let coordinator = HistoryCoordinator() let coordinator = HistoryCoordinator()
let controller = coordinator.start() let (controller, viewModel) = coordinator.start()
controller.tabBarItem = UITabBarItem(title: NSLocalizedString("History", comment: ""), controller.tabBarItem = UITabBarItem(title: NSLocalizedString("History", comment: ""),
image: UIImage(systemName: "clock.arrow.circlepath"), tag: 0) image: UIImage(systemName: "clock.arrow.circlepath"), tag: 0)
viewControllers?[0] = controller viewControllers?[0] = controller
historyViewModel = viewModel
} }
func addSettings() async { func addSettings() async {
@ -53,9 +55,7 @@ class MainTabController: UITabBarController, UITabBarControllerDelegate {
} }
func showCheckPuller() { func showCheckPuller() {
guard let checkNav = viewControllers?.first as? UINavigationController, guard let historyViewModel else {
let checkController = checkNav.viewControllers.first as? CheckController
else {
return return
} }
@ -74,7 +74,7 @@ class MainTabController: UITabBarController, UITabBarControllerDelegate {
newNumberController.onCheck = { number in newNumberController.onCheck = { number in
SwiftEntryKit.dismiss { SwiftEntryKit.dismiss {
self.selectedIndex = 0 self.selectedIndex = 0
checkController.checkTapped(number: number) Task { await historyViewModel.checkNewNumber(number) }
} }
} }

View File

@ -55,6 +55,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
container.register(StorageServiceProtocol.self, container.register(StorageServiceProtocol.self,
instance: try await StorageService(settingsService: settingsService)) instance: try await StorageService(settingsService: settingsService))
container.register(VehicleServiceProtocol.self, instance: VehicleService())
} }
func setupRootController(scene: UIScene) { func setupRootController(scene: UIScene) {

View File

@ -15,12 +15,13 @@ final class HistoryCoordinator {
var navController: UINavigationController? var navController: UINavigationController?
func start() -> UIViewController { func start() -> (UIViewController, HistoryViewModel) {
let resolver = ServiceContainer.shared let resolver = ServiceContainer.shared
let viewModel = HistoryViewModel( let viewModel = HistoryViewModel(
apiService: resolver.resolve(ApiServiceProtocol.self), apiService: resolver.resolve(ApiServiceProtocol.self),
storageService: resolver.resolve(StorageServiceProtocol.self), storageService: resolver.resolve(StorageServiceProtocol.self),
vehicleService: resolver.resolve(VehicleServiceProtocol.self),
coordinator: self coordinator: self
) )
@ -30,7 +31,7 @@ final class HistoryCoordinator {
let navController = UINavigationController(rootViewController: controller) let navController = UINavigationController(rootViewController: controller)
self.navController = navController self.navController = navController
return navController return (navController, viewModel)
} }
func openReport(vehicle: VehicleDto) async { func openReport(vehicle: VehicleDto) async {

View File

@ -15,6 +15,7 @@ final class HistoryViewModel: ACHudContainer {
let apiService: ApiServiceProtocol let apiService: ApiServiceProtocol
let storageService: StorageServiceProtocol let storageService: StorageServiceProtocol
let vehicleService: VehicleServiceProtocol
let coordinator: HistoryCoordinator? let coordinator: HistoryCoordinator?
var hud: ACHud? var hud: ACHud?
@ -45,10 +46,12 @@ final class HistoryViewModel: ACHudContainer {
init(apiService: ApiServiceProtocol, init(apiService: ApiServiceProtocol,
storageService: StorageServiceProtocol, storageService: StorageServiceProtocol,
vehicleService: VehicleServiceProtocol,
coordinator: HistoryCoordinator) { coordinator: HistoryCoordinator) {
self.apiService = apiService self.apiService = apiService
self.storageService = storageService self.storageService = storageService
self.vehicleService = vehicleService
self.coordinator = coordinator self.coordinator = coordinator
Task { await loadVehicles() } Task { await loadVehicles() }
@ -104,4 +107,10 @@ final class HistoryViewModel: ACHudContainer {
} }
} }
} }
func checkNewNumber(_ number: String) async {
await wrapWithToast { [weak self] in
try await self?.vehicleService.checkAndStore(number: number)
}
}
} }

View File

@ -0,0 +1,24 @@
//
// VehicleService.swift
// AutoCatCore
//
// Created by Selim Mustafaev on 19.01.2025.
// Copyright © 2025 Selim Mustafaev. All rights reserved.
//
public final class VehicleService {
public init() {}
}
extension VehicleService: VehicleServiceProtocol {
public func check(number: String) async throws -> VehicleDto {
VehicleDto()
}
public func checkAndStore(number: String) async throws {
}
}

View File

@ -0,0 +1,13 @@
//
// VehicleServiceProtocol.swift
// AutoCatCore
//
// Created by Selim Mustafaev on 19.01.2025.
// Copyright © 2025 Selim Mustafaev. All rights reserved.
//
public protocol VehicleServiceProtocol: Sendable {
func check(number: String) async throws -> VehicleDto
func checkAndStore(number: String) async throws
}