From e0e95a91fe65680a40f8a28b6890383a21f4852f Mon Sep 17 00:00:00 2001 From: InKwon James Kim Date: Tue, 13 Aug 2019 14:08:58 +0900 Subject: [PATCH] AutoDebitModules - apply SwiftLint --- .../Interactor/AddAccountInteractor.swift | 2 - .../Service/AddAccountService.swift | 43 ++++++++++-------- .../Service/AddAccountServiceType.swift | 12 ++--- .../AddAccountModuleInterface.swift | 22 +++++----- .../Presenter/AddAccountPresenter.swift | 2 +- .../View/AddAccountViewController.swift | 18 ++++---- .../Wireframe/AddAccountWireframe.swift | 12 ++--- .../Interactor/AutoDebitInteractor.swift | 44 ++++++++++--------- .../Interactor/AutoDebitInteractorIO.swift | 4 -- .../Service/AutoDebitService.swift | 32 +++++++++----- .../AutoDebitModuleInterface.swift | 1 - .../Presenter/AutoDebitPresenter.swift | 2 +- .../View/AutoDebitViewController.swift | 14 +++--- .../View/AutoDebitViewInterface.swift | 4 -- .../Wireframe/AutoDebitWireframe.swift | 7 ++- 15 files changed, 114 insertions(+), 105 deletions(-) diff --git a/GME Remit/Modules/AutoDebitModules/AddAccount/Application Logic/Interactor/AddAccountInteractor.swift b/GME Remit/Modules/AutoDebitModules/AddAccount/Application Logic/Interactor/AddAccountInteractor.swift index 1f06c43b..3043a6ea 100644 --- a/GME Remit/Modules/AutoDebitModules/AddAccount/Application Logic/Interactor/AddAccountInteractor.swift +++ b/GME Remit/Modules/AutoDebitModules/AddAccount/Application Logic/Interactor/AddAccountInteractor.swift @@ -81,5 +81,3 @@ extension AddAccountInteractor: AddAccountInteractorInput { ) } } - - diff --git a/GME Remit/Modules/AutoDebitModules/AddAccount/Application Logic/Service/AddAccountService.swift b/GME Remit/Modules/AutoDebitModules/AddAccount/Application Logic/Service/AddAccountService.swift index e204469b..21bc3b5a 100644 --- a/GME Remit/Modules/AutoDebitModules/AddAccount/Application Logic/Service/AddAccountService.swift +++ b/GME Remit/Modules/AutoDebitModules/AddAccount/Application Logic/Service/AddAccountService.swift @@ -17,8 +17,9 @@ class AddAccountService: AddAccountServiceType { // MARK: Data management - func fetchBankList(success: @escaping ([BankInformation]?) -> (), - failure: @escaping (Error) -> ()) { + func fetchBankList( + success: @escaping ([BankInformation]?) -> Void, + failure: @escaping (Error) -> Void) { auth.request( method: .get, @@ -33,19 +34,20 @@ class AddAccountService: AddAccountServiceType { ) failure(error) - }else { + } else { success(response.data) } - }) { (error) in - failure(error) - } + }, + failure: { (error) in + failure(error) + } + ) } func verifyAccountService( params: [String: String], - success: @escaping () -> (), - failure: @escaping (Error) -> ()) { - + success: @escaping () -> Void, + failure: @escaping (Error) -> Void) { auth.request( method: .post, url: baseUrl + "/kftc/CheckRealName", @@ -59,20 +61,21 @@ class AddAccountService: AddAccountServiceType { ) failure(error) - }else { + } else { success() } - }) { (error) in - failure(error) - } + }, + failure: { (error) in + failure(error) + } + ) } func fetchKftcUrlService( url: String, header: [String: String], - success: @escaping (String?) -> (), - failure: @escaping (Error) -> ()) { - + success: @escaping (String?) -> Void, + failure: @escaping (Error) -> Void) { auth.kftcRequest( method: .get, header: header, @@ -81,8 +84,10 @@ class AddAccountService: AddAccountServiceType { encoding: URLEncoding.default, success: { (response: KFTCURL) in success(response.value) - }) { (error) in - failure(error) - } + }, + failure: { (error) in + failure(error) + } + ) } } diff --git a/GME Remit/Modules/AutoDebitModules/AddAccount/Application Logic/Service/AddAccountServiceType.swift b/GME Remit/Modules/AutoDebitModules/AddAccount/Application Logic/Service/AddAccountServiceType.swift index 5860db68..94eee759 100644 --- a/GME Remit/Modules/AutoDebitModules/AddAccount/Application Logic/Service/AddAccountServiceType.swift +++ b/GME Remit/Modules/AutoDebitModules/AddAccount/Application Logic/Service/AddAccountServiceType.swift @@ -10,20 +10,20 @@ import Foundation protocol AddAccountServiceType: ApiServiceType { func fetchBankList( - success: @escaping ([BankInformation]?) -> (), - failure: @escaping (Error) -> () + success: @escaping ([BankInformation]?) -> Void, + failure: @escaping (Error) -> Void ) func verifyAccountService( params: [String: String], - success: @escaping () -> (), - failure: @escaping (Error) -> () + success: @escaping () -> Void, + failure: @escaping (Error) -> Void ) func fetchKftcUrlService( url: String, header: [String: String], - success: @escaping (String?) -> (), - failure: @escaping (Error) -> () + success: @escaping (String?) -> Void, + failure: @escaping (Error) -> Void ) } diff --git a/GME Remit/Modules/AutoDebitModules/AddAccount/Module Interface/AddAccountModuleInterface.swift b/GME Remit/Modules/AutoDebitModules/AddAccount/Module Interface/AddAccountModuleInterface.swift index b2aa7c00..c39fa85e 100644 --- a/GME Remit/Modules/AutoDebitModules/AddAccount/Module Interface/AddAccountModuleInterface.swift +++ b/GME Remit/Modules/AutoDebitModules/AddAccount/Module Interface/AddAccountModuleInterface.swift @@ -7,15 +7,15 @@ // protocol AddAccountModuleInterface: class { - func viewIsReady() - - func verifyAccount( - customerID: String, - bankCode: String, - accountNumber: String - ) - - func doGetTestURL(url: String, header: [String: String]) - - func goKFTC(url: String, header: [KftcHeader]?) + func viewIsReady() + + func verifyAccount( + customerID: String, + bankCode: String, + accountNumber: String + ) + + func doGetTestURL(url: String, header: [String: String]) + + func goKFTC(url: String, header: [KftcHeader]?) } diff --git a/GME Remit/Modules/AutoDebitModules/AddAccount/User Interface/Presenter/AddAccountPresenter.swift b/GME Remit/Modules/AutoDebitModules/AddAccount/User Interface/Presenter/AddAccountPresenter.swift index 2078adab..749e3e3b 100644 --- a/GME Remit/Modules/AutoDebitModules/AddAccount/User Interface/Presenter/AddAccountPresenter.swift +++ b/GME Remit/Modules/AutoDebitModules/AddAccount/User Interface/Presenter/AddAccountPresenter.swift @@ -37,7 +37,7 @@ extension AddAccountPresenter: AddAccountModuleInterface { customerID: String, bankCode: String, accountNumber: String - ){ + ) { if customerID == "" || bankCode == "" || accountNumber == "" { let error = NSError.init( diff --git a/GME Remit/Modules/AutoDebitModules/AddAccount/User Interface/View/AddAccountViewController.swift b/GME Remit/Modules/AutoDebitModules/AddAccount/User Interface/View/AddAccountViewController.swift index ed274012..d2cac699 100644 --- a/GME Remit/Modules/AutoDebitModules/AddAccount/User Interface/View/AddAccountViewController.swift +++ b/GME Remit/Modules/AutoDebitModules/AddAccount/User Interface/View/AddAccountViewController.swift @@ -25,7 +25,7 @@ class AddAccountViewController: UIViewController { ] private var isValid = false { - didSet{ + didSet { verifyAccountButton.isEnabled = isValid verifyAccountButton.backgroundColor = isValid ? AppConstants.themeRedColor : .lightGray } @@ -46,7 +46,7 @@ class AddAccountViewController: UIViewController { bankNameTextField.inputView = bankPickerView bankPickerView.backgroundColor = .white - let originalBanks = model.bankList?.map{ $0.bankName ?? "" } + let originalBanks = model.bankList?.map { $0.bankName ?? "" } let originalLanguages = model.kftcModel?.languages?.map { $0.value ?? ""} banks?.append(contentsOf: originalBanks ?? []) @@ -114,7 +114,6 @@ class AddAccountViewController: UIViewController { dismiss(animated: true, completion: nil) } - // MARK: Other Functions private func setup() { @@ -126,8 +125,7 @@ class AddAccountViewController: UIViewController { setMultilanguage() } - - private func setValidTextField(){ + private func setValidTextField() { bankNameTextField.titleFont = UIFont(name: "SanfranciscoDisplay-Regular", size: 13)! bankNameTextField.errorFont = UIFont(name: "SanfranciscoDisplay-Regular", size: 13)! bankNameTextField.addTarget(self, action: #selector(textFieldDidChange(_:)), for: .editingChanged) @@ -145,7 +143,7 @@ class AddAccountViewController: UIViewController { @objc func textFieldDidChange(_ textfield: UITextField) { - let tf = textfield as! ValidationTextField + guard let tf = textfield as? ValidationTextField else { return } switch tf { case bankNameTextField: @@ -158,10 +156,10 @@ class AddAccountViewController: UIViewController { break } - isValid = validDic.reduce(true){ $0 && $1.value} + isValid = validDic.allSatisfy {$0.value} } - private func setMultilanguage(){ + private func setMultilanguage() { closeButton.title = "penny_test_close_text".localized() titleInfoLabel.text = "to_add_account_enter_information".localized() bankNameTextField.placeholder = "select_your_bank".localized() @@ -207,11 +205,11 @@ extension AddAccountViewController: AddAccountViewInterface { alert(type: .error, message: error.localizedDescription, okAction: nil) } - func startLoading(){ + func startLoading() { showProgressHud() } - func endLoading(){ + func endLoading() { hideProgressHud() } } diff --git a/GME Remit/Modules/AutoDebitModules/AddAccount/User Interface/Wireframe/AddAccountWireframe.swift b/GME Remit/Modules/AutoDebitModules/AddAccount/User Interface/Wireframe/AddAccountWireframe.swift index 5d2cf4e2..49a87081 100644 --- a/GME Remit/Modules/AutoDebitModules/AddAccount/User Interface/Wireframe/AddAccountWireframe.swift +++ b/GME Remit/Modules/AutoDebitModules/AddAccount/User Interface/Wireframe/AddAccountWireframe.swift @@ -33,20 +33,20 @@ extension AddAccountWireframe: AddAccountWireframeInput { return viewController } - func openPushMainView(with model: KFTCModel?, source: UIViewController){ + func openPushMainView(with model: KFTCModel?, source: UIViewController) { self.model = model openViewControllerWithNavigation(viewController: getMainView(), source: source) } - func pushKFTCViewControllerOf(url: String, header: [KftcHeader]?){ - let viewcontroller = UIStoryboard.init(name: "WKWebView", bundle: nil).instantiateViewController(withIdentifier: "WkWebViewController") as! WkWebViewController + func pushKFTCViewControllerOf(url: String, header: [KftcHeader]?) { + let viewcontroller = UIStoryboard( + name: "WKWebView", + bundle: nil + ).instantiateViewController(withIdentifier: "WkWebViewController") as! WkWebViewController viewcontroller.url = url viewcontroller.headers = header view.navigationController?.pushViewController(viewcontroller, animated: true) } - - } - diff --git a/GME Remit/Modules/AutoDebitModules/AutoDebit/Application Logic/Interactor/AutoDebitInteractor.swift b/GME Remit/Modules/AutoDebitModules/AutoDebit/Application Logic/Interactor/AutoDebitInteractor.swift index 3b879068..33d55d3e 100644 --- a/GME Remit/Modules/AutoDebitModules/AutoDebit/Application Logic/Interactor/AutoDebitInteractor.swift +++ b/GME Remit/Modules/AutoDebitModules/AutoDebit/Application Logic/Interactor/AutoDebitInteractor.swift @@ -9,19 +9,19 @@ import Foundation class AutoDebitInteractor { - - // MARK: Properties - - weak var output: AutoDebitInteractorOutput? - private let service: AutoDebitServiceType - - // MARK: Initialization - - init(service: AutoDebitServiceType) { - self.service = service - } - - // MARK: Converting entities + + // MARK: Properties + + weak var output: AutoDebitInteractorOutput? + private let service: AutoDebitServiceType + + // MARK: Initialization + + init(service: AutoDebitServiceType) { + self.service = service + } + + // MARK: Converting entities } // MARK: AutoDebit interactor input interface @@ -31,7 +31,7 @@ extension AutoDebitInteractor: AutoDebitInteractorInput { guard let userId = GMEDB.shared.user.string(.userId) else { return - } + } self.service.fetchAccountList( username: userId, @@ -75,7 +75,10 @@ extension AutoDebitInteractor: AutoDebitInteractorInput { service.refreshTokenStep1( username: email, success: { response in - let url = "\(response?.url?.replacingOccurrences(of: "&lang=", with: "&lang=\(language.key ?? "eng")") ?? "")" + let url = response?.url?.replacingOccurrences( + of: "&lang=", with: "&lang=\(language.key ?? "eng")" + ) ?? "" + var header = [String: String]() response?.header?.forEach({ header[$0.key ?? ""] = $0.value ?? "" @@ -86,16 +89,15 @@ extension AutoDebitInteractor: AutoDebitInteractorInput { header: header, success: { self.output?.refreshTokenSuccess(header: response?.header, url: $0) - }, + }, failure: { self.output?.refreshTokenError(with: $0) - } - ) - - }, + } + ) + }, failure: { self.output?.refreshTokenError(with: $0) - } + } ) } } diff --git a/GME Remit/Modules/AutoDebitModules/AutoDebit/Application Logic/Interactor/AutoDebitInteractorIO.swift b/GME Remit/Modules/AutoDebitModules/AutoDebit/Application Logic/Interactor/AutoDebitInteractorIO.swift index b634e0c8..f15e9de2 100644 --- a/GME Remit/Modules/AutoDebitModules/AutoDebit/Application Logic/Interactor/AutoDebitInteractorIO.swift +++ b/GME Remit/Modules/AutoDebitModules/AutoDebit/Application Logic/Interactor/AutoDebitInteractorIO.swift @@ -30,7 +30,6 @@ protocol AutoDebitInteractorOutput: class { /// If did success delete KFTC bank account func didDeleteAccount() - /// If did fail delete KFTC bank account func didFailDeleteAccount(with error: Error) @@ -40,19 +39,16 @@ protocol AutoDebitInteractorOutput: class { /// - Parameter model: KFTCModel func setModel(with model: KFTCModel?) - /// If did fail fetch KFTC bank account list /// /// - Parameter error: Error func didFailSetModel(with error: Error) - /// If did fail refreshToken /// /// - Parameter error: Error func refreshTokenError(with error: Error) - /// if Succeess then get url for refresh token /// /// - Parameter url: String diff --git a/GME Remit/Modules/AutoDebitModules/AutoDebit/Application Logic/Service/AutoDebitService.swift b/GME Remit/Modules/AutoDebitModules/AutoDebit/Application Logic/Service/AutoDebitService.swift index 2e04049b..ac6e83ff 100644 --- a/GME Remit/Modules/AutoDebitModules/AutoDebit/Application Logic/Service/AutoDebitService.swift +++ b/GME Remit/Modules/AutoDebitModules/AutoDebit/Application Logic/Service/AutoDebitService.swift @@ -31,9 +31,13 @@ class AutoDebitService: AutoDebitServiceType { encoding: URLEncoding.default, success: { (response: KftcAccountContainer) in if (response.errorCode ?? "") == "1" { - let error = NSError.init(domain: "Network", code: 0, userInfo: [NSLocalizedDescriptionKey : response.message ?? ""]) + let error = NSError( + domain: "Network", + code: 0, + userInfo: [NSLocalizedDescriptionKey : response.message ?? ""] + ) failure(error) - }else { + } else { let model = response.data success(model) } @@ -61,13 +65,17 @@ class AutoDebitService: AutoDebitServiceType { encoding: JSONEncoding.default, success: { (response: KftcAccountContainer) in if (response.errorCode ?? "") == "1" { - let error = NSError.init(domain: "Network", code: 0, userInfo: [NSLocalizedDescriptionKey : response.message ?? ""]) + let error = NSError( + domain: "Network", + code: 0, + userInfo: [NSLocalizedDescriptionKey : response.message ?? ""] + ) failure(error) - }else { + } else { success() } }, - failure:{ (error) in + failure: { (error) in failure(error) } ) @@ -77,7 +85,7 @@ class AutoDebitService: AutoDebitServiceType { username: String, success: @escaping (KFTCModel?) -> Void, failure: @escaping (Error) -> Void - ) { + ) { let url = baseUrl + "/kftc/CheckKFTCAccounts/" + username auth.request( @@ -87,16 +95,20 @@ class AutoDebitService: AutoDebitServiceType { encoding: URLEncoding.default, success: { (response: KftcAccountContainer) in if (response.errorCode ?? "") == "1" { - let error = NSError.init(domain: "Network", code: 0, userInfo: [NSLocalizedDescriptionKey : response.message ?? ""]) + let error = NSError( + domain: "Network", + code: 0, + userInfo: [NSLocalizedDescriptionKey : response.message ?? ""] + ) failure(error) - }else { + } else { let model = response.data success(model) } - }, + }, failure: { (error) in failure(error) - } + } ) } } diff --git a/GME Remit/Modules/AutoDebitModules/AutoDebit/Module Interface/AutoDebitModuleInterface.swift b/GME Remit/Modules/AutoDebitModules/AutoDebit/Module Interface/AutoDebitModuleInterface.swift index 38c95ae4..2017b1d2 100644 --- a/GME Remit/Modules/AutoDebitModules/AutoDebit/Module Interface/AutoDebitModuleInterface.swift +++ b/GME Remit/Modules/AutoDebitModules/AutoDebit/Module Interface/AutoDebitModuleInterface.swift @@ -11,7 +11,6 @@ protocol AutoDebitModuleInterface: class { /// Fetch KFTC registed bank account list func fetchKFTCBankAccountList() - /// Delete selected KFTC bank account /// /// - Parameters: diff --git a/GME Remit/Modules/AutoDebitModules/AutoDebit/User Interface/Presenter/AutoDebitPresenter.swift b/GME Remit/Modules/AutoDebitModules/AutoDebit/User Interface/Presenter/AutoDebitPresenter.swift index f05e83ab..78ac6405 100644 --- a/GME Remit/Modules/AutoDebitModules/AutoDebit/User Interface/Presenter/AutoDebitPresenter.swift +++ b/GME Remit/Modules/AutoDebitModules/AutoDebit/User Interface/Presenter/AutoDebitPresenter.swift @@ -62,7 +62,7 @@ extension AutoDebitPresenter: AutoDebitInteractorOutput { view?.didFailSetModel(with: error) } - func didDeleteAccount(){ + func didDeleteAccount() { view?.endLoading() view?.didDeleteAccount() } diff --git a/GME Remit/Modules/AutoDebitModules/AutoDebit/User Interface/View/AutoDebitViewController.swift b/GME Remit/Modules/AutoDebitModules/AutoDebit/User Interface/View/AutoDebitViewController.swift index 1902dd9e..bf66972e 100644 --- a/GME Remit/Modules/AutoDebitModules/AutoDebit/User Interface/View/AutoDebitViewController.swift +++ b/GME Remit/Modules/AutoDebitModules/AutoDebit/User Interface/View/AutoDebitViewController.swift @@ -66,7 +66,7 @@ class AutoDebitViewController: UIViewController { labelSwipeInfo.isHidden = true viewAddAccount.isHidden = true return - } + } tableView.isHidden = false labelSwipeInfo.isHidden = false @@ -84,7 +84,7 @@ class AutoDebitViewController: UIViewController { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - + setupNormalNavigation() navigationItem.title = multiLanguages.navigationTitle @@ -146,19 +146,17 @@ class AutoDebitViewController: UIViewController { self.tableView.refreshControl?.endRefreshing() } - }, + }, cancelAction: { DispatchQueue.main.asyncAfter(deadline: .now()) {[weak self] in guard let `self` = self else {return} self.tableView.refreshControl?.endRefreshing() } - } + } ) } @IBAction func touchClose(_ sender: UIBarButtonItem) { - //FIXME: For Test -// GMEDB.shared.user.set("", .redirectTo) dismiss(animated: true, completion: nil) } @@ -180,7 +178,7 @@ class AutoDebitViewController: UIViewController { configureText() view.addSubview(languageTextField) -// addRefreshControlTableView() + // addRefreshControlTableView() } @@ -218,7 +216,7 @@ extension AutoDebitViewController: UITableViewDelegate { func tableView( _ tableView: UITableView, editActionsForRowAt indexPath: IndexPath - ) -> [UITableViewRowAction]? { + ) -> [UITableViewRowAction]? { let delete = UITableViewRowAction( style: .destructive, title: multiLanguages.deleteText diff --git a/GME Remit/Modules/AutoDebitModules/AutoDebit/User Interface/View/AutoDebitViewInterface.swift b/GME Remit/Modules/AutoDebitModules/AutoDebit/User Interface/View/AutoDebitViewInterface.swift index b2ab59ec..c89e9843 100644 --- a/GME Remit/Modules/AutoDebitModules/AutoDebit/User Interface/View/AutoDebitViewInterface.swift +++ b/GME Remit/Modules/AutoDebitModules/AutoDebit/User Interface/View/AutoDebitViewInterface.swift @@ -13,17 +13,14 @@ protocol AutoDebitViewInterface: class { /// - Parameter model: KFTCModel func setModel(with model: KFTCModel?) - /// If did fail fetch KFTC bank account list /// /// - Parameter error: Error func didFailSetModel(with error: Error) - /// If did success delete KFTC bank account func didDeleteAccount() - /// If did fail delete KFTC bank account /// /// - Parameter error: Error @@ -34,7 +31,6 @@ protocol AutoDebitViewInterface: class { /// Start ActivityIndicator func startLoading() - /// Stop ActivityIndicator func endLoading() } diff --git a/GME Remit/Modules/AutoDebitModules/AutoDebit/User Interface/Wireframe/AutoDebitWireframe.swift b/GME Remit/Modules/AutoDebitModules/AutoDebit/User Interface/Wireframe/AutoDebitWireframe.swift index cdaf75ad..71b14251 100644 --- a/GME Remit/Modules/AutoDebitModules/AutoDebit/User Interface/Wireframe/AutoDebitWireframe.swift +++ b/GME Remit/Modules/AutoDebitModules/AutoDebit/User Interface/Wireframe/AutoDebitWireframe.swift @@ -37,7 +37,12 @@ extension AutoDebitWireframe: AutoDebitWireframeInput { } func goRefreshToken(header: [KftcHeader]?, url: String?) { - let viewcontroller = UIStoryboard.init(name: "WKWebView", bundle: nil).instantiateViewController(withIdentifier: "WkWebViewController") as! WkWebViewController + guard let viewcontroller = UIStoryboard( + name: "WKWebView", + bundle: nil + ).instantiateViewController(withIdentifier: "WkWebViewController") as? WkWebViewController else { + return + } viewcontroller.url = url?.components(separatedBy: .whitespaces).joined() viewcontroller.headers = header