diff --git a/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthAPI.swift b/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthAPI.swift index 06d2855d..36ebb1bd 100644 --- a/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthAPI.swift +++ b/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthAPI.swift @@ -118,4 +118,20 @@ public class AuthAPI { return .networkFail } } + + func withdrawal(completion: @escaping (NetworkResult) -> Void) { + userProvider.request(.withdrawal) { result in + switch result { + case .success(let response): + let statusCode = response.statusCode + let data = response.data + + let networkResult = self.judgeStatus(by: statusCode, data) + completion(networkResult) + + case .failure(let err): + print(err) + } + } + } } diff --git a/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthService.swift b/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthService.swift index 5e998ac8..91d88c55 100644 --- a/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthService.swift +++ b/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthService.swift @@ -12,6 +12,7 @@ enum AuthService { case signup(socialID: String, profileImg: UIImage?, nickname: String, fcmToken: String) case login(socialID: String, fcmToken: String) case signout + case withdrawal } extension AuthService: TargetType { @@ -27,6 +28,8 @@ extension AuthService: TargetType { return "/auth/doorbell" case .signout: return "/auth/signout" + case .withdrawal: + return "/auth/user" } } @@ -38,6 +41,8 @@ extension AuthService: TargetType { return .get case .signout: return .post + case .withdrawal: + return .delete } } @@ -64,6 +69,8 @@ extension AuthService: TargetType { encoding: URLEncoding.queryString) case .signout: return .requestPlain + case .withdrawal: + return .requestPlain } } @@ -75,6 +82,8 @@ extension AuthService: TargetType { return Const.Header.basicHeader() case .signout: return Const.Header.authorizationHeader() + case .withdrawal: + return Const.Header.authorizationHeader() } } } diff --git a/Spark-iOS/Spark-iOS/Source/ViewControllers/Mypage/WithdrawalVC.swift b/Spark-iOS/Spark-iOS/Source/ViewControllers/Mypage/WithdrawalVC.swift index 7bf14f20..40730d4c 100644 --- a/Spark-iOS/Spark-iOS/Source/ViewControllers/Mypage/WithdrawalVC.swift +++ b/Spark-iOS/Spark-iOS/Source/ViewControllers/Mypage/WithdrawalVC.swift @@ -99,21 +99,22 @@ extension WithdrawalVC { @objc private func touchWithdrawalButtonButton() { - // TODO: - 탈퇴하기 서버통신 guard let dialogueVC = UIStoryboard(name: Const.Storyboard.Name.dialogue, bundle: nil).instantiateViewController(withIdentifier: Const.ViewController.Identifier.dialogue) as? DialogueVC else { return } dialogueVC.modalPresentationStyle = .overFullScreen dialogueVC.modalTransitionStyle = .crossDissolve dialogueVC.dialogueType = .withdrawal dialogueVC.clousure = { - if UserDefaults.standard.bool(forKey: Const.UserDefaultsKey.isAppleLogin) { - self.unlink() - } else { - UserApi.shared.unlink { error in - if let error = error { - print("kakao unlink error: \(error).") - } else { - // unlink success. - self.unlink() + self.withdrawalWithAPI { + if UserDefaults.standard.bool(forKey: Const.UserDefaultsKey.isAppleLogin) { + self.unlink() + } else { + UserApi.shared.unlink { error in + if let error = error { + print("kakao unlink error: \(error).") + } else { + // unlink success. + self.unlink() + } } } } @@ -144,3 +145,26 @@ extension WithdrawalVC { } } } + +// MARK: - Network + +extension WithdrawalVC { + private func withdrawalWithAPI(completion: @escaping () -> Void) { + AuthAPI.shared.withdrawal { response in + switch response { + case .success(let message): + completion() + + print("withdrawalWithAPI - success: \(message)") + case .requestErr(let message): + print("withdrawalWithAPI - requestErr: \(message)") + case .pathErr: + print("withdrawalWithAPI - pathErr") + case .serverErr: + print("withdrawalWithAPI - serverErr") + case .networkFail: + print("withdrawalWithAPI - networkFail") + } + } + } +}