diff --git a/AutoCat.xcodeproj/project.pbxproj b/AutoCat.xcodeproj/project.pbxproj index 40e2c18..134404d 100644 --- a/AutoCat.xcodeproj/project.pbxproj +++ b/AutoCat.xcodeproj/project.pbxproj @@ -728,7 +728,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 53; + CURRENT_PROJECT_VERSION = 54; DEVELOPMENT_TEAM = 46DTTB8X4S; INFOPLIST_FILE = AutoCat/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; @@ -750,7 +750,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 53; + CURRENT_PROJECT_VERSION = 54; DEVELOPMENT_TEAM = 46DTTB8X4S; INFOPLIST_FILE = AutoCat/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; diff --git a/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcschemes/xcschememanagement.plist b/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcschemes/xcschememanagement.plist index 1d0f546..5eb0487 100644 --- a/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcschemes/xcschememanagement.plist @@ -14,35 +14,35 @@ isShown orderHint - 8 + 5 DifferenceKit (Playground) 2.xcscheme isShown orderHint - 9 + 6 DifferenceKit (Playground).xcscheme isShown orderHint - 7 + 4 Eureka (Playground) 1.xcscheme isShown orderHint - 5 + 2 Eureka (Playground) 2.xcscheme isShown orderHint - 6 + 3 Eureka (Playground) 3.xcscheme @@ -70,7 +70,7 @@ isShown orderHint - 4 + 1 GettingStarted (Playground) 1.xcscheme @@ -112,42 +112,42 @@ isShown orderHint - 11 + 13 Rx (Playground) 1.xcscheme isShown orderHint - 2 + 8 Rx (Playground) 2.xcscheme isShown orderHint - 3 + 9 Rx (Playground).xcscheme isShown orderHint - 1 + 7 SwiftDate (Playground) 1.xcscheme isShown orderHint - 12 + 10 SwiftDate (Playground) 2.xcscheme isShown orderHint - 13 + 12 SwiftDate (Playground) 3.xcscheme @@ -175,7 +175,7 @@ isShown orderHint - 10 + 11 SuppressBuildableAutocreation diff --git a/AutoCat/Controllers/CheckController.swift b/AutoCat/Controllers/CheckController.swift index 691035f..97cea1e 100644 --- a/AutoCat/Controllers/CheckController.swift +++ b/AutoCat/Controllers/CheckController.swift @@ -74,7 +74,17 @@ class CheckController: UIViewController, UITableViewDelegate, UITextFieldDelegat if let event = event { action = .sendSpecific(event) } - self.check(number: number, action: action).subscribe().disposed(by: self.bag) + //self.check(number: number, action: action).subscribe().disposed(by: self.bag) + HUD.show(.progress) + self.check(number: number, action: action).subscribe { vehicle in + self.updateDetailController(with: vehicle) + HUD.hide() + } onError: { error in + HUD.hide() + self.show(error: error) + //HUD.show(error: error) + } + .disposed(by: self.bag) break case .addVoiceRecord: self.tabBarController?.selectedIndex = 1 @@ -105,7 +115,9 @@ class CheckController: UIViewController, UITableViewDelegate, UITextFieldDelegat self.updateDetailController(with: vehicle) HUD.hide() } onError: { error in - HUD.show(error: error) + HUD.hide() + self.show(error: error) + //HUD.show(error: error) } .disposed(by: self.bag) @@ -210,7 +222,9 @@ class CheckController: UIViewController, UITableViewDelegate, UITextFieldDelegat self.updateDetailController(with: vehicle) HUD.hide() } onError: { error in - HUD.show(error: error) + HUD.hide() + self.show(error: error) + //HUD.show(error: error) } .disposed(by: self.bag) } @@ -277,14 +291,24 @@ class CheckController: UIViewController, UITableViewDelegate, UITextFieldDelegat return checkSingle } else { return checkSingle - .flatMap { _ in self.getEvent(for: action) } - .flatMap { event in event.findAddress().map{ event }.catchErrorJustReturn(event) } - .flatMap { Api.add(event: $0, to: number) } + .flatMap { self.addEvent(to: $0, action: action) } + } + } + + func addEvent(to vehicle: Vehicle, action: EventAction) -> Single { + return self.getEvent(for: action).flatMap { event in + return event + .findAddress() + .map{ event } + .catchErrorJustReturn(event) + .flatMap { Api.add(event: $0, to: vehicle.freeze().getNumber()) } .observeOn(MainScheduler.instance) .map { try self.save(vehicle: $0) return $0 } + .catchErrorJustReturn(vehicle) } + .catchErrorJustReturn(vehicle) } } diff --git a/AutoCat/Models/Response.swift b/AutoCat/Models/Response.swift index a66a87a..979efd6 100644 --- a/AutoCat/Models/Response.swift +++ b/AutoCat/Models/Response.swift @@ -15,12 +15,7 @@ class Response: Decodable where T: Decodable { let container = try decoder.container(keyedBy: CodingKeys.self) success = try container.decode(Bool.self, forKey: .success) if success { - do { - data = try container.decode(T.self, forKey: .data) - } catch { - print(error) - data = nil - } + data = try container.decode(T.self, forKey: .data) error = nil } else { error = try container.decode(String.self, forKey: .error) diff --git a/AutoCat/Models/Vehicle.swift b/AutoCat/Models/Vehicle.swift index a920a6d..540eb8a 100644 --- a/AutoCat/Models/Vehicle.swift +++ b/AutoCat/Models/Vehicle.swift @@ -162,8 +162,8 @@ class Vehicle: Object, Decodable, Identifiable, Differentiable { self.vin2 = try container.decodeIfPresent(String.self, forKey: .vin2) self.sts = try container.decodeIfPresent(String.self, forKey: .sts) self.pts = try container.decodeIfPresent(String.self, forKey: .pts) - self.isRightWheel = try container.decode(RealmOptional.self, forKey: .isRightWheel) - self.isJapanese = try container.decode(RealmOptional.self, forKey: .isJapanese) + self.isRightWheel = RealmOptional(try container.decodeIfPresent(Bool.self, forKey: .isRightWheel)) + self.isJapanese = RealmOptional(try container.decodeIfPresent(Bool.self, forKey: .isJapanese)) self.addedDate = (try container.decode(TimeInterval.self, forKey: .addedDate))/1000 self.addedBy = try container.decode(String.self, forKey: .addedBy) diff --git a/AutoCat/Utils/Api.swift b/AutoCat/Utils/Api.swift index 1a587ab..ba88af3 100644 --- a/AutoCat/Utils/Api.swift +++ b/AutoCat/Utils/Api.swift @@ -40,7 +40,7 @@ class Api { } return URLSession.shared.rx.data(request: request).asSingle().map { data in - let str = String(data: data, encoding: .utf8) +// let str = String(data: data, encoding: .utf8) // print("================================") // if let string = str?.replacingOccurrences(of: "\\\"", with: "\"") // .replacingOccurrences(of: "\\'", with: "'") @@ -48,11 +48,17 @@ class Api { // print(string) // } // print("================================") - let resp = try JSONDecoder().decode(Response.self, from: data) - if resp.success { - return resp.data! - } else { - throw self.genError(resp.error!, suggestion: "") + do { + let resp = try JSONDecoder().decode(Response.self, from: data) + if resp.success { + return resp.data! + } else { + throw self.genError(resp.error!, suggestion: "") + } + } catch let error as Swift.DecodingError { + throw CocoaError.error((error as CustomDebugStringConvertible).debugDescription) + } catch { + throw error } } } diff --git a/AutoCat/Utils/Constants.swift b/AutoCat/Utils/Constants.swift index fd8bd02..34e7169 100644 --- a/AutoCat/Utils/Constants.swift +++ b/AutoCat/Utils/Constants.swift @@ -3,9 +3,9 @@ import Foundation enum Constants { static var baseUrl: String { #if DEBUG - //return "http://127.0.0.1:3000/" + return "http://127.0.0.1:3000/" //return "http://192.168.1.67:3000/" - return "https://vps.aliencat.pro:8443/" + //return "https://vps.aliencat.pro:8443/" #else return "https://vps.aliencat.pro:8443/" #endif