From d87db81dc56d137f9e7b28f7af56c9d137f2d41e Mon Sep 17 00:00:00 2001 From: InKwon James Kim Date: Mon, 12 Aug 2019 11:58:26 +0900 Subject: [PATCH] add APIRouter --- GME Remit.xcodeproj/project.pbxproj | 16 ++ GME Remit/APIs/CommonServiceType.swift | 39 ++- GME Remit/APIs/ExchangeRateApiService.swift | 63 +++-- GME Remit/APIs/Router/APIRouter.swift | 266 ++++++++++++++++++ GME Remit/AppDelegate.swift | 2 +- .../Models/ExchangeRateRequestModel.swift | 19 ++ .../View/ExchangeRatesViewController.swift | 16 +- .../Service/ForgotPasswordServiceType.swift | 28 +- .../Interactor/HomeInteractor.swift | 36 +-- .../Service/HomeServiceType.swift | 42 +-- .../Service/LoginService.swift | 45 ++- .../Service/SetupRecipientService.swift | 4 +- .../Service/SetupRecipientServiceType.swift | 2 +- .../View/PennyTestSubmitViewController.swift | 12 +- .../Interactor/RegisterInteractor.swift | 11 +- .../Service/RegisterServiceType.swift | 41 ++- .../Service/RedeemService.swift | 14 +- .../Interactor/SplashScreenInteractor.swift | 4 +- .../Interactor/SplashScreenInteractorIO.swift | 2 +- .../SplashScreenModuleInterface.swift | 2 +- .../Presenter/SplashScreenPresenter.swift | 4 +- .../View/SplashScreenViewController.swift | 14 +- 22 files changed, 514 insertions(+), 168 deletions(-) create mode 100644 GME Remit/APIs/Router/APIRouter.swift create mode 100644 GME Remit/Models/ExchangeRateRequestModel.swift diff --git a/GME Remit.xcodeproj/project.pbxproj b/GME Remit.xcodeproj/project.pbxproj index fb58d07e..8914d957 100644 --- a/GME Remit.xcodeproj/project.pbxproj +++ b/GME Remit.xcodeproj/project.pbxproj @@ -195,6 +195,7 @@ 73157BA422DC1EEC009B836F /* PopupNotificationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73157B9922DC1EEC009B836F /* PopupNotificationViewController.swift */; }; 73157BA522DC1EEC009B836F /* PopupNotification.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 73157B9A22DC1EEC009B836F /* PopupNotification.storyboard */; }; 73157BA722DC3F14009B836F /* Date+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73157BA622DC3F14009B836F /* Date+Ext.swift */; }; + 731627A52301009800BA48A8 /* ExchangeRateRequestModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 731627A42301009800BA48A8 /* ExchangeRateRequestModel.swift */; }; 73168A1F22F3CC4C00878038 /* NativeCountry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73168A1E22F3CC4B00878038 /* NativeCountry.swift */; }; 73168A2322F3D01A00878038 /* TablePresenterProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73168A2222F3D01900878038 /* TablePresenterProtocol.swift */; }; 73195AB222FD14D500151434 /* SetupRecipientModuleInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73195A9D22FD14D400151434 /* SetupRecipientModuleInterface.swift */; }; @@ -209,6 +210,7 @@ 73195ABB22FD14D500151434 /* SetupRecipientViewModelInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73195AAF22FD14D400151434 /* SetupRecipientViewModelInterface.swift */; }; 73195ABC22FD14D500151434 /* SetupRecipient.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 73195AB022FD14D400151434 /* SetupRecipient.storyboard */; }; 73195ABD22FD14D500151434 /* SetupRecipientViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73195AB122FD14D400151434 /* SetupRecipientViewController.swift */; }; + 73195B3522FD5BC600151434 /* APIRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73195B3422FD5BC600151434 /* APIRouter.swift */; }; 73210DA122FBE73100715D6C /* RecipientsModuleInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73210D8E22FBE73100715D6C /* RecipientsModuleInterface.swift */; }; 73210DA222FBE73100715D6C /* RecipientsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73210D9222FBE73100715D6C /* RecipientsService.swift */; }; 73210DA322FBE73100715D6C /* RecipientsServiceType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73210D9322FBE73100715D6C /* RecipientsServiceType.swift */; }; @@ -2418,6 +2420,7 @@ 73157B9922DC1EEC009B836F /* PopupNotificationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PopupNotificationViewController.swift; sourceTree = ""; }; 73157B9A22DC1EEC009B836F /* PopupNotification.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = PopupNotification.storyboard; sourceTree = ""; }; 73157BA622DC3F14009B836F /* Date+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+Ext.swift"; sourceTree = ""; }; + 731627A42301009800BA48A8 /* ExchangeRateRequestModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ExchangeRateRequestModel.swift; path = "GME Remit/Models/ExchangeRateRequestModel.swift"; sourceTree = ""; }; 73168A1E22F3CC4B00878038 /* NativeCountry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NativeCountry.swift; sourceTree = ""; }; 73168A2222F3D01900878038 /* TablePresenterProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TablePresenterProtocol.swift; sourceTree = ""; }; 73195A9D22FD14D400151434 /* SetupRecipientModuleInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SetupRecipientModuleInterface.swift; sourceTree = ""; }; @@ -2432,6 +2435,7 @@ 73195AAF22FD14D400151434 /* SetupRecipientViewModelInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SetupRecipientViewModelInterface.swift; sourceTree = ""; }; 73195AB022FD14D400151434 /* SetupRecipient.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = SetupRecipient.storyboard; sourceTree = ""; }; 73195AB122FD14D400151434 /* SetupRecipientViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SetupRecipientViewController.swift; sourceTree = ""; }; + 73195B3422FD5BC600151434 /* APIRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIRouter.swift; sourceTree = ""; }; 73210D8E22FBE73100715D6C /* RecipientsModuleInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecipientsModuleInterface.swift; sourceTree = ""; }; 73210D9222FBE73100715D6C /* RecipientsService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecipientsService.swift; sourceTree = ""; }; 73210D9322FBE73100715D6C /* RecipientsServiceType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecipientsServiceType.swift; sourceTree = ""; }; @@ -5709,6 +5713,14 @@ path = View; sourceTree = ""; }; + 731627A623010C5B00BA48A8 /* Router */ = { + isa = PBXGroup; + children = ( + 73195B3422FD5BC600151434 /* APIRouter.swift */, + ); + path = Router; + sourceTree = ""; + }; 73168A1B22F3C9E300878038 /* ThirdParty */ = { isa = PBXGroup; children = ( @@ -6676,6 +6688,7 @@ 9FD260EB1FD00458007A511D = { isa = PBXGroup; children = ( + 731627A42301009800BA48A8 /* ExchangeRateRequestModel.swift */, D94838D421757F8C00FFC19E /* GME Remit.entitlements */, 9FD260F61FD00458007A511D /* GME Remit */, 9FD2610B1FD00458007A511D /* GME RemitTests */, @@ -10890,6 +10903,7 @@ D96848CA212D3F1200EF12B1 /* APIs */ = { isa = PBXGroup; children = ( + 731627A623010C5B00BA48A8 /* Router */, D96848CD212D419400EF12B1 /* ApiServiceType.swift */, 73538B2122EFC5FA00188CDD /* CommonServiceType.swift */, D96848CB212D3F2300EF12B1 /* ExchangeRateApiService.swift */, @@ -14233,6 +14247,7 @@ 73FE8838228A4A8C00A5EB56 /* OrderHistoryService.swift in Sources */, BEC9B000224FC49C00A2DA06 /* BiometricAuthenticationInteractor.swift in Sources */, D945F11D213E1D5100A24824 /* SendMoneyReceiptModuleInterface.swift in Sources */, + 73195B3522FD5BC600151434 /* APIRouter.swift in Sources */, 73A6E20222CEE51600E9BC68 /* BadgeAppearance.swift in Sources */, D97785AA215DD04400754079 /* TransactionHistoryTableViewCell.swift in Sources */, 730D7894227A94E1007E517E /* RewardItemCollectionViewCell.swift in Sources */, @@ -14310,6 +14325,7 @@ 730197A322535135001954AB /* kycForm3Service.swift in Sources */, D922D96C2135145F00D43053 /* SendMoneyParentViewController.swift in Sources */, D922D98C21351AAE00D43053 /* SendMoneyExchangeRateViewController.swift in Sources */, + 731627A52301009800BA48A8 /* ExchangeRateRequestModel.swift in Sources */, D922D9402135124200D43053 /* SendMoneyPaymentModeModuleInterface.swift in Sources */, D92E6569222620A0004D1B3D /* SendMoneyCodeService.swift in Sources */, BEC9B001224FC49C00A2DA06 /* BiometricAuthenticationPresenter.swift in Sources */, diff --git a/GME Remit/APIs/CommonServiceType.swift b/GME Remit/APIs/CommonServiceType.swift index bbd7c23f..46c953ee 100644 --- a/GME Remit/APIs/CommonServiceType.swift +++ b/GME Remit/APIs/CommonServiceType.swift @@ -24,28 +24,23 @@ extension CommonServiceType { idNumber: String = "", idType: String = "", success: @escaping (Bool, String?) -> Void, - failure: @escaping (Error) -> () - ) { - let url = "http://gmeuat.gmeremit.com:5022/api/v3/validation" - let paramaters = [ - "Username": userName, - "IdNumber": idNumber, - "IdType": idType - ] - - auth.request( - method: .post, - url: url, - params: paramaters, - needsAuthorization: false, - success: { (response: ResponseMessage) in - if (response.errorCode ?? "") == "1" { - success(false, response.message) - }else { - success(true, nil) - } - }, - failure: { failure($0) } + failure: @escaping (Error) -> Void + ) { + APIRouter.validation( + userName: userName, + idNumber: idNumber, + idType: idType ) + .request( + needsAuthorization: false, + success: { (response: ResponseMessage) in + if (response.errorCode ?? "") == "1" { + success(false, response.message) + }else { + success(true, nil) + } + }, + failure: { failure($0)} + ) } } diff --git a/GME Remit/APIs/ExchangeRateApiService.swift b/GME Remit/APIs/ExchangeRateApiService.swift index f9995bab..a7660791 100644 --- a/GME Remit/APIs/ExchangeRateApiService.swift +++ b/GME Remit/APIs/ExchangeRateApiService.swift @@ -17,39 +17,56 @@ protocol FetchCountryCurrencyInformation: ApiServiceType { extension FetchCountryCurrencyInformation { func fetchCountryCurrencyInfo(isAuth: Bool = true, success: @escaping ([ExchangeRateModel]?) -> (), failure: @escaping (Error) -> ()) { - let url = baseUrl + "/mobile/countriesServices" - auth.request(method: .get, url: url , params: nil, needsAuthorization: isAuth, success: { (response: ExchangeRateContainer) in - if (response.errorCode ?? "") == "1" { - let error = NSError.init(domain: "Network", code: 0, userInfo: [NSLocalizedDescriptionKey : response.message ?? ""]) - failure(error) - }else { - let model = response.data - success(model) - } - }) { (error) in + + APIRouter + .countriesServices + .request( + needsAuthorization: isAuth, + success: { (response: ExchangeRateContainer) in + if (response.errorCode ?? "") == "1" { + let error = NSError(domain: "Network", code: 0, message: response.message ?? "") failure(error) - } - } + } else { + let model = response.data + success(model) + } + }, + failure: {failure($0)} + ) + } } protocol getExchangeRateInformation: ApiServiceType { - func getExchangeRateInformation(isAuth: Bool, params: [String: String], success: @escaping (ExchangeRateDetailModel?) -> (), failure: @escaping (Error) -> ()) + func getExchangeRateInformation( + isAuth: Bool, + model: ExchangeRateRequestModel, + success: @escaping (ExchangeRateDetailModel?) -> (), + failure: @escaping (Error) -> () + ) } extension getExchangeRateInformation { - func getExchangeRateInformation(isAuth: Bool = true, params: [String: String], success: @escaping (ExchangeRateDetailModel?) -> (), failure: @escaping (Error) -> () ) { - let url = baseUrl + "/mobile/calculateDefExRate" - - auth.request(method: .post, url: url, params: params, needsAuthorization: isAuth, success: { (response: ExchangeRateDetailContainer) in + func getExchangeRateInformation( + isAuth: Bool = true, + model: ExchangeRateRequestModel, + success: @escaping (ExchangeRateDetailModel?) -> (), + failure: @escaping (Error) -> () + ) { + APIRouter.calculateDefExRate(model: model) + .request( + needsAuthorization: isAuth, + success: { (response: ExchangeRateDetailContainer) in if (response.errorCode ?? "") == "1" { - let error = NSError.init(domain: "Network", code: 0, userInfo: [NSLocalizedDescriptionKey : response.message ?? ""]) - failure(error) + let error = NSError(domain: "Network", code: 0, message: response.message ?? "") + failure(error) }else { - let model = response.data - success(model) + let model = response.data + success(model) } - }, failure: failure) - } + }, + failure: failure + ) + } } diff --git a/GME Remit/APIs/Router/APIRouter.swift b/GME Remit/APIs/Router/APIRouter.swift new file mode 100644 index 00000000..de64a804 --- /dev/null +++ b/GME Remit/APIs/Router/APIRouter.swift @@ -0,0 +1,266 @@ +// +// APIRouter.swift +// GME Remit +// +// Created by InKwon James Kim on 09/08/2019. +// Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved. +// + +import Foundation +import Alamofire +import Localize_Swift +import ObjectMapper + +enum APIRouter: ApiServiceType { + case accesscode(username: String, password: String) + case customerProfile(firebaseToken: String) + case customerRegister(registerModel: RegisterRequestModel, firebaseToken: String) + case passwordReset(userName: String) + case validation(userName: String, idNumber: String, idType: String) + case countriesServices + case calculateDefExRate(model: ExchangeRateRequestModel) + case recipientRequirement(country: String) +} + +extension APIRouter { + private var manager: SessionManager { + let manager = Alamofire.SessionManager.default + manager.session.configuration.timeoutIntervalForRequest = 150 + + return manager + } + + private var uuid: String { + guard let uuid = GMEDB.shared.app.string(.uuid) else { + let uuid = UUID().uuidString + GMEDB.shared.app.set(uuid, .uuid) + return uuid + } + + return uuid + } + + private var beforeLoginHeader: [String: String] { + let currentLanguage = Localize.currentLanguage() + let lang = Utility.getLanguageHeader(for: currentLanguage) + let authValue = "172017F9EC11222E8107142733:QRK2UM0Q:\(uuid)".toBase64() + + return [ + "Authorization": "Basic \(authValue)", + "GME-TOKEN" : "39587YT398@FBQOW8RY3#948R7GB@CNEQW987GF87$TD18$1981..919@@##joghndvberteiru", + "Content-Type": "application/json", + "lang" : lang + ] + } + + private var afterLoginHeader: [String: String] { + let accessCode = GMEDB.shared.user.string(.accessCode) ?? "" + let currentLanguage = Localize.currentLanguage() + let lang = Utility.getLanguageHeader(for: currentLanguage) + + return [ + "Authorization": "Bearer " + accessCode, + "GME-TOKEN" : "39587YT398@FBQOW8RY3#948R7GB@CNEQW987GF87$TD18$1981..919@@##joghndvberteiru", + "Content-Type": "application/json", + "clientId": Utility.getMyKftcClientId(), + "lang" : lang + ] + } + + func request( + encoding: ParameterEncoding = JSONEncoding.default, + needsAuthorization: Bool = true, + success: @escaping (T) -> Void, + failure: @escaping (Error) -> Void + ) { + guard + let isReachable = NetworkReachabilityManager()?.isReachable, + isReachable else { + let error = NSError( + domain: "NETWORK_REACHABILITY_DOMAIN", + code: -99, + message: "No Internet connection found. Check your connection." + ) + return failure(error) + } + + manager.request( + self.endpoint, + method: self.method, + parameters: self.parameters, + encoding: encoding, + headers: needsAuthorization ? afterLoginHeader : beforeLoginHeader + ).handle(success: success, failure: failure) + } + + func kftcRequest( + method: HTTPMethod, + header: [String: String], + url: String, + params: [String: Any]?, + encoding: ParameterEncoding = JSONEncoding.default, + needsAuthorization: Bool = true, + success: @escaping (T) -> Void, + failure: @escaping (Error) -> Void + ) { + guard + let isReachable = NetworkReachabilityManager()?.isReachable, + isReachable else { + let error = NSError( + domain: "NETWORK_REACHABILITY_DOMAIN", + code: -99, + message: "No Internet connection found. Check your connection." + ) + return failure(error) + } + + manager.request( + url, + method: method, + parameters: params, + encoding: encoding, + headers: header + ).handle(success: success, failure: failure) + + } + + func requestMultipart( + method: HTTPMethod, + _ URLString: URLConvertible, + parameters: [String: String]? = nil, + images: [String: Data], + encoding: Alamofire.ParameterEncoding = URLEncoding.default, + needsAuthorization: Bool = true, + success: @escaping (T)-> Void, + failure: @escaping (Error) -> Void + ) { + guard + let isReachable = NetworkReachabilityManager()?.isReachable, + isReachable else { + let error = NSError( + domain: "NETWORK_REACHABILITY_DOMAIN", + code: -99, + message: "No Internet connection found. Check your connection." + ) + return failure(error) + } + + manager.upload( + multipartFormData: { multipartFormData in + if !images.isEmpty { + images.forEach({ (data) in + multipartFormData.append(data.value, withName: data.key, fileName: data.key + ".jpeg", mimeType: "image/jpeg") + }) + + } + parameters?.forEach { (params) in + multipartFormData.append(params.value.data(using: String.Encoding.utf8, allowLossyConversion: false)!, withName: params.key) + } + }, + to: URLString, + method: method, + headers: needsAuthorization ? afterLoginHeader : beforeLoginHeader, + encodingCompletion: { encodingResult in + switch encodingResult { + case .success(let upload, _, _): + upload.handle(success: success, failure: failure) + case .failure: + let error = NSError( + domain: "NETWORK_REACHABILITY_DOMAIN", + code: -99, + message: "No Internet connection found. Check your connection." + ) + failure(error) + } + } + ) + } +} + +extension APIRouter { + private var endpoint: String { + switch self { + case .accesscode: return "\(baseUrl)/users/access-code" + case .customerProfile: return "\(baseUrl)/mobile/CustomerProfile" + case .customerRegister: return "\(baseUrlWithoutVersion)/v3/mobile/customerRegister" + case .passwordReset: return "\(baseUrl)/mobile/passwordReset" + case .validation: return "\(baseUrlWithoutVersion)/v3/validation" + case .countriesServices: return "\(baseUrl)/mobile/countriesServices" + case .calculateDefExRate: return "\(baseUrl)/mobile/calculateDefExRate" + case .recipientRequirement(let country): return "\(country)" + } + } + + private var method: HTTPMethod { + switch self { + case .accesscode: return .post + case .customerProfile: return .post + case .customerRegister: return .post + case .passwordReset: return .post + case .validation: return .post + case .countriesServices: return .get + case .calculateDefExRate: return .post + case .recipientRequirement: return .get + } + } + + private var parameters: Parameters? { + switch self { + case .accesscode(let username, let password): + return [ + "userId": username, + "password": password + ] + + case .customerProfile(let firebaseToken): + return [ + "userId" : Utility.getMyUserName(), + "uuid": self.uuid, + "appVersion": Utility.getAppVersion() ?? "", + "phoneBrand": Utility.getPhoneBrand(), + "phoneOs": Utility.getPhoneOs(), + "fcmId": firebaseToken, + "osVersion": Utility.getOsVersion() + ] + + case .customerRegister(let registerModel, let firebaseToken): + return [ + "username": registerModel.username ?? "", + "password": registerModel.encryptedPassword ?? "", + "nativecountry": registerModel.nativeCountry ?? "", + "mobilenumber": registerModel.mobileNumber ?? "", + "clientId": Utility.getCliendId(), + "uuid": self.uuid, + "appVersion": Utility.getAppVersion() ?? "", + "phoneBrand": Utility.getPhoneBrand(), + "phoneOs": Utility.getPhoneOs(), + "fcmId": firebaseToken, + "osVersion": Utility.getOsVersion() + ] + + case .passwordReset(let userName): + return ["username": userName] + + case .validation(let userName, let idNumber, let idType): + return [ + "Username": userName, + "IdNumber": idNumber, + "IdType": idType + ] + case .countriesServices: return nil + case .calculateDefExRate(let model): + return [ + "cAmount" : model.senderAmount, + "sCurrency" : model.senderCurrency, + "pAmount" : model.recipientAmount, + "pCurrency" : model.recipientCurrency, + "pCountry" : model.recipientCountryID, + "serviceType": model.serviceType, + "calcBy" : model.calcBy, + "sCountry" : model.senderCountryID, + "pCountryName": model.recipientCountry + ] + case .recipientRequirement: return nil + } + } +} diff --git a/GME Remit/AppDelegate.swift b/GME Remit/AppDelegate.swift index be550335..21eabc8c 100644 --- a/GME Remit/AppDelegate.swift +++ b/GME Remit/AppDelegate.swift @@ -21,7 +21,7 @@ import LGSideMenuController import Localize_Swift import ChannelIO -let server: Server = .staging +let server: Server = .live var overlayView: UIView? @UIApplicationMain diff --git a/GME Remit/Models/ExchangeRateRequestModel.swift b/GME Remit/Models/ExchangeRateRequestModel.swift new file mode 100644 index 00000000..b21c5013 --- /dev/null +++ b/GME Remit/Models/ExchangeRateRequestModel.swift @@ -0,0 +1,19 @@ +// +// ExchangeRateRequestModel.swift +// GME Remit +// +// Created by InKwon James Kim on 12/08/2019. +// Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved. +// + +struct ExchangeRateRequestModel { + let senderAmount: String + let senderCurrency: String + let senderCountryID: String + let recipientAmount: String + let recipientCurrency: String + let recipientCountryID: String + let recipientCountry: String + let serviceType: String + let calcBy: String +} diff --git a/GME Remit/Modules/ExchangeRates/User Interface/View/ExchangeRatesViewController.swift b/GME Remit/Modules/ExchangeRates/User Interface/View/ExchangeRatesViewController.swift index 4f258c31..9d0fed2f 100644 --- a/GME Remit/Modules/ExchangeRates/User Interface/View/ExchangeRatesViewController.swift +++ b/GME Remit/Modules/ExchangeRates/User Interface/View/ExchangeRatesViewController.swift @@ -186,11 +186,21 @@ class ExchangeRatesViewController: UIViewController { ApiConstants.senderCountryId : senderCountryId ?? "", ApiConstants.recieverCountryName: recieverCountryName ?? "" ] - // print(param) - // todo + + let model = ExchangeRateRequestModel( + senderAmount: (senderAmt ?? "").stringRemovingComma(), + senderCurrency: (senderCurrency ?? ""), + senderCountryID: senderCountryId ?? "", + recipientAmount: (recieverAmt ?? "").stringRemovingComma(), + recipientCurrency: recieverCurrency ?? "", + recipientCountryID: recieverCountryId ?? "", + recipientCountry: recieverCountryName ?? "", + serviceType: paymentMethod ?? "", + calcBy: calcBy ?? "" + ) if shouldShowLoading { self.showProgressHud() } - self.getExchangeRateInformation(params: param, success: { (exchageRateDetail) in + self.getExchangeRateInformation(model: model, success: { (exchageRateDetail) in self.reciepientTextField.text = Utility.getCommaSeperatedStringWithDecimal(numberString: exchageRateDetail?.recipientAmount ?? "") self.senderTextField.text = Utility.getCommaSeperatedStringWithDecimal(numberString: exchageRateDetail?.senderAmount ?? "") diff --git a/GME Remit/Modules/ForgotPassword/Application Logic/Service/ForgotPasswordServiceType.swift b/GME Remit/Modules/ForgotPassword/Application Logic/Service/ForgotPasswordServiceType.swift index a36c5237..6b27eab9 100644 --- a/GME Remit/Modules/ForgotPassword/Application Logic/Service/ForgotPasswordServiceType.swift +++ b/GME Remit/Modules/ForgotPassword/Application Logic/Service/ForgotPasswordServiceType.swift @@ -20,20 +20,22 @@ protocol PasswordResetService: ApiServiceType { extension PasswordResetService { func reset(username: String, dob: String, success: @escaping (String) -> (), failure: @escaping (Error) -> ()) { - let url = baseUrl + "/mobile/passwordReset" - let params = ["username": username,"Dob": dob] - - auth.request(method: .post, url: url, params: params, needsAuthorization: false, success: { (response: ResponseMessage) in - if (response.errorCode ?? "") == "1" { - let error = NSError.init(domain: "Network", code: 0, userInfo: [NSLocalizedDescriptionKey : response.message ?? ""]) - failure(error) - }else { - let model = response.message ?? "" - success(model) - } - }) { (error) in + + APIRouter + .passwordReset(userName: username) + .request( + needsAuthorization: false, + success: { (response: ResponseMessage) in + if (response.errorCode ?? "") == "1" { + let error = NSError.init(domain: "Network", code: 0, userInfo: [NSLocalizedDescriptionKey : response.message ?? ""]) failure(error) - } + }else { + let model = response.message ?? "" + success(model) + } + }, + failure: { failure($0) } + ) } } diff --git a/GME Remit/Modules/Home/Application Logic/Interactor/HomeInteractor.swift b/GME Remit/Modules/Home/Application Logic/Interactor/HomeInteractor.swift index 9ad6d75e..6acb0e70 100644 --- a/GME Remit/Modules/Home/Application Logic/Interactor/HomeInteractor.swift +++ b/GME Remit/Modules/Home/Application Logic/Interactor/HomeInteractor.swift @@ -32,28 +32,20 @@ extension HomeInteractor: HomeInteractorInput { func fetchUserInfo() { GMEDB.shared.getFcmToken { (token, error) in - let userId = Utility.getMyUserName() - var param = ["userId" : userId] - - param["uuid"] = Utility.getUUid() ?? "" - param["appVersion"] = Utility.getAppVersion() - param["phoneBrand"] = Utility.getPhoneBrand() - param["phoneOs"] = Utility.getPhoneOs() - param["fcmId"] = token ?? "" - param["osVersion"] = Utility.getOsVersion() - - self.service.fetchUserInfo(param: param, success: { user in - self.output?.show(model: user) - - }) { error in - if let _error = error as? NSError { - if _error.code == AppConstants.emergencyLogoutErrorCode { + self.service.fetchUserInfo( + token: token ?? "", + success: { user in + self.output?.show(model: user) + }, + failure: { + let error = $0 as NSError + if error.code == AppConstants.emergencyLogoutErrorCode { self.output?.show(panicError: error) + return } - return - } - self.output?.show(error: error) - } + + self.output?.show(error: error) + }) } } @@ -61,10 +53,10 @@ extension HomeInteractor: HomeInteractorInput { service.fetchHotLines( success: { self.output?.setHotLine(with: $0) - }, + }, failure: { self.output?.show(error: $0) - } + } ) } } diff --git a/GME Remit/Modules/Home/Application Logic/Service/HomeServiceType.swift b/GME Remit/Modules/Home/Application Logic/Service/HomeServiceType.swift index ffa842d6..4bdac423 100644 --- a/GME Remit/Modules/Home/Application Logic/Service/HomeServiceType.swift +++ b/GME Remit/Modules/Home/Application Logic/Service/HomeServiceType.swift @@ -16,28 +16,38 @@ protocol HomeServiceType: class, UserInfoService { protocol UserInfoService: ApiServiceType { - func fetchUserInfo(param: [String: String], success: @escaping (User) -> (), failure: @escaping (Error) -> ()) + func fetchUserInfo(token: String, success: @escaping (User) -> (), failure: @escaping (Error) -> ()) } extension UserInfoService { - func fetchUserInfo(param: [String: String], success: @escaping (User) -> (), failure: @escaping (Error) -> ()) { - let url = baseUrl + "/mobile/CustomerProfile" - auth.request(method: .post, url: url, params: param, success: { (response: UserContainer ) in + func fetchUserInfo(token: String, success: @escaping (User) -> (), failure: @escaping (Error) -> ()) { + APIRouter + .customerProfile(firebaseToken: token) + .request( + success: { (response: UserContainer) in if (response.errorCode ?? "") == "1" { - let error = NSError.init(domain: "Network", code: AppConstants.emergencyLogoutErrorCode, userInfo: [NSLocalizedDescriptionKey : response.message ?? ""]) + let error = NSError( + domain: "NetWork", + code: AppConstants.emergencyLogoutErrorCode, + message: response.message ?? "" + ) + failure(error) + } else { + if let model = response.data { + success(model) + } else { + let error = NSError( + domain: "NetWork", + code: AppConstants.emergencyLogoutErrorCode, + message: response.message ?? "" + ) failure(error) - }else { - if let model = response.data { - success(model) - }else { - let error = NSError.init(domain: "UserInfoService", code: AppConstants.emergencyLogoutErrorCode, userInfo: [NSLocalizedDescriptionKey : response.message ?? ""]) - failure(error) - } - + } + } - }) { (error) in - failure(error) - } + }, + failure: {failure($0)} + ) } } diff --git a/GME Remit/Modules/Login/Application Logic/Service/LoginService.swift b/GME Remit/Modules/Login/Application Logic/Service/LoginService.swift index b49355cb..c3c2f7b7 100644 --- a/GME Remit/Modules/Login/Application Logic/Service/LoginService.swift +++ b/GME Remit/Modules/Login/Application Logic/Service/LoginService.swift @@ -23,19 +23,40 @@ protocol LoginApiService: ApiServiceType { } extension LoginApiService { - func _login(userId: String, password: String, success: @escaping (User?) -> (), failure: @escaping (Error) -> ()) { - let params = [ "userId": userId, "password": password ] - let url = baseUrl + "/users/access-code" - auth.request(method: .post, url: url, params: params,needsAuthorization: false, success: { (response: UserContainer ) in + func _login( + userId: String, + password: String, + success: @escaping (User?) -> (), + failure: @escaping (Error) -> () + ) { + APIRouter + .accesscode(username: userId, password: password) + .request( + needsAuthorization: false, + success: {(response: UserContainer ) in if (response.errorCode ?? "") == "1" { - let error = NSError.init(domain: "Network", code: 0, userInfo: [NSLocalizedDescriptionKey : response.message ?? ""]) - failure(error) - }else { - let model = response.data - success(model) + let error = NSError.init(domain: "Network", code: 0, userInfo: [NSLocalizedDescriptionKey : response.message ?? ""]) + failure(error) + } else { + let model = response.data + success(model) } - }) { (error) in - failure(error) - } + }, + failure: {failure($0)} + ) + +// let params = [ "userId": userId, "password": password ] +// let url = baseUrl + "/users/access-code" +// auth.request(method: .post, url: url, params: params,needsAuthorization: false, success: { (response: UserContainer ) in +// if (response.errorCode ?? "") == "1" { +// let error = NSError.init(domain: "Network", code: 0, userInfo: [NSLocalizedDescriptionKey : response.message ?? ""]) +// failure(error) +// }else { +// let model = response.data +// success(model) +// } +// }) { (error) in +// failure(error) +// } } } diff --git a/GME Remit/Modules/RecipientModules/SetupRecipient/Application Logic/Service/SetupRecipientService.swift b/GME Remit/Modules/RecipientModules/SetupRecipient/Application Logic/Service/SetupRecipientService.swift index 0ae08780..5c73081a 100644 --- a/GME Remit/Modules/RecipientModules/SetupRecipient/Application Logic/Service/SetupRecipientService.swift +++ b/GME Remit/Modules/RecipientModules/SetupRecipient/Application Logic/Service/SetupRecipientService.swift @@ -9,5 +9,7 @@ import Foundation class SetupRecipientService: SetupRecipientServiceType { - + func fetchRecipientRequirement(of country: String) { + APIRouter.recipientRequirement(country: country) + } } diff --git a/GME Remit/Modules/RecipientModules/SetupRecipient/Application Logic/Service/SetupRecipientServiceType.swift b/GME Remit/Modules/RecipientModules/SetupRecipient/Application Logic/Service/SetupRecipientServiceType.swift index 27f68b7c..5ce4381e 100644 --- a/GME Remit/Modules/RecipientModules/SetupRecipient/Application Logic/Service/SetupRecipientServiceType.swift +++ b/GME Remit/Modules/RecipientModules/SetupRecipient/Application Logic/Service/SetupRecipientServiceType.swift @@ -7,5 +7,5 @@ // protocol SetupRecipientServiceType: class { - + func fetchRecipientRequirement(of country: String) } diff --git a/GME Remit/Modules/RegisterModules/PennyTestSubmit/User Interface/View/PennyTestSubmitViewController.swift b/GME Remit/Modules/RegisterModules/PennyTestSubmit/User Interface/View/PennyTestSubmitViewController.swift index 4af1fe4b..41495ed7 100644 --- a/GME Remit/Modules/RegisterModules/PennyTestSubmit/User Interface/View/PennyTestSubmitViewController.swift +++ b/GME Remit/Modules/RegisterModules/PennyTestSubmit/User Interface/View/PennyTestSubmitViewController.swift @@ -233,17 +233,7 @@ class PennyTestSubmitViewController: UIViewController { func fetchUserInfo() { GMEDB.shared.getFcmToken { (token, error) in - let userId = Utility.getMyUserName() - var param = ["userId" : userId] - - param["uuid"] = Utility.getUUid() ?? "" - param["appVersion"] = Utility.getAppVersion() - param["phoneBrand"] = Utility.getPhoneBrand() - param["phoneOs"] = Utility.getPhoneOs() - param["fcmId"] = token ?? "" - param["osVersion"] = Utility.getOsVersion() - - self.fetchUserInfo(param: param, success: { user in + self.fetchUserInfo(token: token ?? "", success: { user in self.navigationController?.popToRootViewController(animated: true) }) { error in self.navigationController?.popToRootViewController(animated: true) diff --git a/GME Remit/Modules/RegisterModules/Register/Application Logic/Interactor/RegisterInteractor.swift b/GME Remit/Modules/RegisterModules/Register/Application Logic/Interactor/RegisterInteractor.swift index c35bdc90..9a0396af 100644 --- a/GME Remit/Modules/RegisterModules/Register/Application Logic/Interactor/RegisterInteractor.swift +++ b/GME Remit/Modules/RegisterModules/Register/Application Logic/Interactor/RegisterInteractor.swift @@ -28,21 +28,12 @@ extension RegisterInteractor: RegisterInteractorInput { func register(model: RegisterRequestModel) { GMEDB.shared.getFcmToken { (token, error) in - model.uuid = Utility.getUUid() - model.appVersion = Utility.getAppVersion() - model.phoneBrand = Utility.getPhoneBrand() - model.phoneOs = Utility.getPhoneOs() - model.osVersion = Utility.getOsVersion() - model.fcmId = token ?? "" - model.clientId = Utility.getCliendId() - - self.service.register(params: model.serialize(), success: { (message) in + self.service.register(model: model, token: token ?? "", success: { (message) in self.output?.success(message: message ?? "") }) { (error) in self.output?.show(error: error) } } - } func checkDuplicate(userName: String) { diff --git a/GME Remit/Modules/RegisterModules/Register/Application Logic/Service/RegisterServiceType.swift b/GME Remit/Modules/RegisterModules/Register/Application Logic/Service/RegisterServiceType.swift index d29ab602..559fc332 100644 --- a/GME Remit/Modules/RegisterModules/Register/Application Logic/Service/RegisterServiceType.swift +++ b/GME Remit/Modules/RegisterModules/Register/Application Logic/Service/RegisterServiceType.swift @@ -14,24 +14,39 @@ protocol RegisterServiceType: class, CommonServiceType, RegisterUserService { } protocol RegisterUserService: ApiServiceType { - func register(params: [String: String], success: @escaping (String?) -> (), failure: @escaping (Error) -> ()) + func register( + model: RegisterRequestModel, + token: String, + success: @escaping (String?) -> Void, + failure: @escaping (Error) -> Void + ) } extension RegisterUserService { - func register(params: [String: String], success: @escaping (String?) -> (), failure: @escaping (Error) -> ()) { - // FIXME: change URL -// let url = baseUrl + "/mobile/customerRegister" - let url = "https://mobileapi.gmeremit.com:8002/api/v3/mobile/customerRegister" - auth.request(method: .post, url: url, params: params, needsAuthorization: false, success: { (response: ResponseMessage) in + func register( + model: RegisterRequestModel, + token: String, + success: @escaping (String?) -> Void, + failure: @escaping (Error) -> Void + ) { + + APIRouter + .customerRegister( + registerModel: model, + firebaseToken: token + ) + .request( + needsAuthorization: false, + success: {(response: ResponseMessage) in if (response.errorCode ?? "") == "1" { - let error = NSError.init(domain: "Network", code: 0, userInfo: [NSLocalizedDescriptionKey : response.message ?? ""]) - failure(error) - }else { - success(response.message) + let error = NSError(domain: "Network", code: 0, message: response.message ?? "") + failure(error) + } else { + success(response.message) } - }) { (error) in - failure(error) - } + }, + failure: {failure($0)} + ) } } diff --git a/GME Remit/Modules/RewardModules/Redeem/Application Logic/Service/RedeemService.swift b/GME Remit/Modules/RewardModules/Redeem/Application Logic/Service/RedeemService.swift index e8a0de6c..fcf9a478 100644 --- a/GME Remit/Modules/RewardModules/Redeem/Application Logic/Service/RedeemService.swift +++ b/GME Remit/Modules/RewardModules/Redeem/Application Logic/Service/RedeemService.swift @@ -94,19 +94,7 @@ class RedeemService: RedeemServiceType { GMEDB.shared.getFcmToken { (token, error) in guard let error = error else { - - let param = [ - "userId" : Utility.getMyUserName(), - "uuid": Utility.getUUid() ?? "", - "appVersion": Utility.getAppVersion() ?? "", - "phoneBrand": Utility.getPhoneBrand(), - "phoneOs": Utility.getPhoneOs(), - "fcmId": token ?? "", - "osVersion": Utility.getOsVersion() - ] - - service.fetchUserInfo(param: param, success: success, failure: failure) - + service.fetchUserInfo(token: token ?? "", success: success, failure: failure) return } diff --git a/GME Remit/Modules/SplashScreen/Application Logic/Interactor/SplashScreenInteractor.swift b/GME Remit/Modules/SplashScreen/Application Logic/Interactor/SplashScreenInteractor.swift index 31641a1f..836d96c5 100644 --- a/GME Remit/Modules/SplashScreen/Application Logic/Interactor/SplashScreenInteractor.swift +++ b/GME Remit/Modules/SplashScreen/Application Logic/Interactor/SplashScreenInteractor.swift @@ -34,10 +34,10 @@ extension SplashScreenInteractor: SplashScreenInteractorInput { ) } - func exchangeCalculate(use param: [String: String]) { + func exchangeCalculate(use model: ExchangeRateRequestModel) { service.getExchangeRateInformation( isAuth: false, - params: param, + model: model, success: { self.output?.setModel(with: $0) }, failure: { self.output?.setError(with: $0) } ) diff --git a/GME Remit/Modules/SplashScreen/Application Logic/Interactor/SplashScreenInteractorIO.swift b/GME Remit/Modules/SplashScreen/Application Logic/Interactor/SplashScreenInteractorIO.swift index ce5001fb..d0170e7f 100644 --- a/GME Remit/Modules/SplashScreen/Application Logic/Interactor/SplashScreenInteractorIO.swift +++ b/GME Remit/Modules/SplashScreen/Application Logic/Interactor/SplashScreenInteractorIO.swift @@ -8,7 +8,7 @@ protocol SplashScreenInteractorInput: class { func fetchExchangeRate() - func exchangeCalculate(use param: [String: String]) + func exchangeCalculate(use model: ExchangeRateRequestModel) } protocol SplashScreenInteractorOutput: class { diff --git a/GME Remit/Modules/SplashScreen/Module Interface/SplashScreenModuleInterface.swift b/GME Remit/Modules/SplashScreen/Module Interface/SplashScreenModuleInterface.swift index e8d023d4..56dc22f4 100644 --- a/GME Remit/Modules/SplashScreen/Module Interface/SplashScreenModuleInterface.swift +++ b/GME Remit/Modules/SplashScreen/Module Interface/SplashScreenModuleInterface.swift @@ -11,5 +11,5 @@ protocol SplashScreenModuleInterface: class { func register() func fetchExchangeRate() - func exchangeCalculate(use param: [String: String]) + func exchangeCalculate(use model: ExchangeRateRequestModel) } diff --git a/GME Remit/Modules/SplashScreen/User Interface/Presenter/SplashScreenPresenter.swift b/GME Remit/Modules/SplashScreen/User Interface/Presenter/SplashScreenPresenter.swift index fe1d9d4c..07b5283f 100644 --- a/GME Remit/Modules/SplashScreen/User Interface/Presenter/SplashScreenPresenter.swift +++ b/GME Remit/Modules/SplashScreen/User Interface/Presenter/SplashScreenPresenter.swift @@ -35,9 +35,9 @@ extension SplashScreenPresenter: SplashScreenModuleInterface { interactor?.fetchExchangeRate() } - func exchangeCalculate(use param: [String: String]) { + func exchangeCalculate(use model: ExchangeRateRequestModel) { view?.showLoading() - interactor?.exchangeCalculate(use: param) + interactor?.exchangeCalculate(use: model) } } diff --git a/GME Remit/Modules/SplashScreen/User Interface/View/SplashScreenViewController.swift b/GME Remit/Modules/SplashScreen/User Interface/View/SplashScreenViewController.swift index 178ecc71..90023ad9 100644 --- a/GME Remit/Modules/SplashScreen/User Interface/View/SplashScreenViewController.swift +++ b/GME Remit/Modules/SplashScreen/User Interface/View/SplashScreenViewController.swift @@ -516,7 +516,19 @@ extension SplashScreenViewController { "pCountryName": selectedExchangeRateModel?.country ?? "" ] - presenter?.exchangeCalculate(use: param) + let model = ExchangeRateRequestModel( + senderAmount: (senderTextField.text ?? "").stringRemovingComma(), + senderCurrency: "KRW", + senderCountryID: "118", + recipientAmount: (recipientTextField.text ?? "").stringRemovingComma(), + recipientCurrency: selectedExchangeRateModel?.currency ?? "", + recipientCountryID: selectedExchangeRateModel?.countryId ?? "", + recipientCountry: selectedExchangeRateModel?.country ?? "", + serviceType: selectedExchangeRateModel?.availableServices?.elementAt(index: selectedPaymentModeIndex)?.id ?? "", + calcBy: calcBy + ) + + presenter?.exchangeCalculate(use: model) } private func showExchangeRateInfomation(isHidden flag: Bool) {