From b1affc64cb0067eaf865ed7f56d70a80ddda411d Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Sat, 16 Mar 2024 17:53:11 +0300 Subject: [PATCH] Adding GB bot integration --- .../xcdebugger/Breakpoints_v2.xcbkptlist | 57 ------------------- AutoCat/Controllers/ReportController.swift | 32 +++++++++++ AutoCat/ru.lproj/Localizable.strings | 8 ++- AutoCatCore/Utils/Api.swift | 4 ++ 4 files changed, 42 insertions(+), 59 deletions(-) diff --git a/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 130aa24..897aeb7 100644 --- a/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -14,16 +14,6 @@ symbolName = "UITableViewAlertForLayoutOutsideViewHierarchy" moduleName = ""> - - @@ -41,53 +31,6 @@ endingLineNumber = "37" landmarkName = "configurePickerStyle(_:_:)" landmarkType = "7"> - - - - - - - - diff --git a/AutoCat/Controllers/ReportController.swift b/AutoCat/Controllers/ReportController.swift index 0b9bf09..1ae284c 100644 --- a/AutoCat/Controllers/ReportController.swift +++ b/AutoCat/Controllers/ReportController.swift @@ -6,6 +6,8 @@ import Eureka import AutoCatCore import SwiftEntryKit import MobileCoreServices +import PKHUD +import RxSwift class ReportController: FormViewController, MediaBrowserViewControllerDataSource, MediaBrowserViewControllerDelegate, UIActivityItemSource { @@ -42,6 +44,8 @@ class ReportController: FormViewController, MediaBrowserViewControllerDataSource } } + let bag = DisposeBag() + // MARK: - Lifecycle override func viewDidLoad() { @@ -154,6 +158,11 @@ class ReportController: FormViewController, MediaBrowserViewControllerDataSource <<< SourceStatusRow("DebugNomerogram") { $0.title = NSLocalizedString("Nomerogram", comment: "") } } + form +++ Section("") + <<< ButtonRow("CheckGB") { $0.title = NSLocalizedString("Check GB", comment: "") }.onCellSelection { cell, row in + self.checkGB() + } + setupCopyBehaviour() } @@ -270,6 +279,29 @@ class ReportController: FormViewController, MediaBrowserViewControllerDataSource self.updateReport() } + func checkGB() { + guard let vehicle = self.vehicle else { return } + + HUD.show(.progress) + Api.checkVehicleGb(by: vehicle.getNumber()).observe(on: MainScheduler.instance).subscribe(onSuccess: { newVehicle in + if let realm = vehicle.realm, !vehicle.isFrozen { + try? realm.write { + realm.add(newVehicle, update: .all) + } + } else { + self.vehicle?.vin1 = newVehicle.vin1 + self.vehicle?.color = newVehicle.color + self.vehicle?.sts = newVehicle.sts + } + self.updateReport() + self.form.allSections.forEach { $0.reload() } + HUD.hide() + }, onFailure: { error in + HUD.hide() + self.show(error: error) + }).disposed(by: self.bag) + } + // MARK: - MediaBrowserViewControllerDataSource & MediaBrowserViewControllerDelegate func numberOfItems(in mediaBrowser: MediaBrowserViewController) -> Int { diff --git a/AutoCat/ru.lproj/Localizable.strings b/AutoCat/ru.lproj/Localizable.strings index e04f531..05791b2 100644 --- a/AutoCat/ru.lproj/Localizable.strings +++ b/AutoCat/ru.lproj/Localizable.strings @@ -70,6 +70,9 @@ /* No comment provided by engineer. */ "Check date" = "Дата проверки"; +/* No comment provided by engineer. */ +"Check GB" = "Получить данные из бота ГБ"; + /* No comment provided by engineer. */ "Check number" = "Проверить номер"; @@ -94,6 +97,9 @@ /* No comment provided by engineer. */ "Copy" = "Копировать"; +/* No comment provided by engineer. */ +"Copy link to report" = "Копировать ссылку на отчет"; + /* No comment provided by engineer. */ "Copy to pasteboard" = "Копировать в буфер обмена"; @@ -403,5 +409,3 @@ /* No comment provided by engineer. */ "ZIP (or OKTMO) code" = "Индекс (или ОКТМО)"; -/* No comment provided by engineer. */ -"Copy link to report" = "Копировать ссылку на отчет"; diff --git a/AutoCatCore/Utils/Api.swift b/AutoCatCore/Utils/Api.swift index 711c862..cdf3f58 100644 --- a/AutoCatCore/Utils/Api.swift +++ b/AutoCatCore/Utils/Api.swift @@ -304,4 +304,8 @@ public class Api { public static func remove(note id: String) -> Single { return self.makeBodyRequest(api: "notes", body: ["noteId": id], method: "DELETE") } + + public static func checkVehicleGb(by number: String) -> Single { + return self.makeBodyRequest(api: "vehicles/checkGbTg", body: ["number": number]) + } }