From 0777c9bd1785843de85d96e5c810e90a26236e6e Mon Sep 17 00:00:00 2001 From: Sejin Lee Date: Sat, 29 Apr 2023 01:16:10 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20#129=20-=20=ED=9A=8C=EC=9B=90=20?= =?UTF-8?q?=ED=83=88=ED=87=B4=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runnect-iOS.xcodeproj/project.pbxproj | 6 ++- .../Network/Dto/MyPageDto/.gitkeep | 0 .../Dto/MyPageDto/UserDeleteResponseDto.swift | 12 +++++ .../Network/Router/UserRouter.swift | 7 ++- .../MyPage/VC/SettingVC/PersonalInfoVC.swift | 46 ++++++++++++++++++- 5 files changed, 66 insertions(+), 5 deletions(-) delete mode 100644 Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/.gitkeep create mode 100644 Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/UserDeleteResponseDto.swift diff --git a/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj b/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj index 267f3dbe..ab7a239f 100644 --- a/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj +++ b/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj @@ -145,6 +145,7 @@ CEEC6B492961C5E200D00E1E /* SplashVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEEC6B482961C5E200D00E1E /* SplashVC.swift */; }; CEEC6B4B2961D89700D00E1E /* CustomNavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEEC6B4A2961D89700D00E1E /* CustomNavigationBar.swift */; }; CEF3CD9A296DB305002723A1 /* CourseDetailResponseDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEF3CD99296DB305002723A1 /* CourseDetailResponseDto.swift */; }; + CEFA9A2F29FC263700F2D0CF /* UserDeleteResponseDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEFA9A2E29FC263700F2D0CF /* UserDeleteResponseDto.swift */; }; DA20D847296697A600F1581F /* MyCourseSelectVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA20D846296697A600F1581F /* MyCourseSelectVC.swift */; }; DA20D849296697B400F1581F /* CourseUploadVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA20D848296697B400F1581F /* CourseUploadVC.swift */; }; DA20D84E2966A9B300F1581F /* CourseSearchVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA20D84D2966A9B300F1581F /* CourseSearchVC.swift */; }; @@ -186,7 +187,6 @@ CE0C23782966D6AF00B45063 /* ViewPager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewPager.swift; sourceTree = ""; }; CE0D9FD229648DA300CEB5CD /* CustomAlertVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomAlertVC.swift; sourceTree = ""; }; CE10063929680C5700FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; - CE10063D29680C8100FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; CE10064D29680D2500FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; CE10064F29680D3300FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; CE10065029680D3800FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; @@ -308,6 +308,7 @@ CEEC6B482961C5E200D00E1E /* SplashVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashVC.swift; sourceTree = ""; }; CEEC6B4A2961D89700D00E1E /* CustomNavigationBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomNavigationBar.swift; sourceTree = ""; }; CEF3CD99296DB305002723A1 /* CourseDetailResponseDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseDetailResponseDto.swift; sourceTree = ""; }; + CEFA9A2E29FC263700F2D0CF /* UserDeleteResponseDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDeleteResponseDto.swift; sourceTree = ""; }; DA20D846296697A600F1581F /* MyCourseSelectVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyCourseSelectVC.swift; sourceTree = ""; }; DA20D848296697B400F1581F /* CourseUploadVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseUploadVC.swift; sourceTree = ""; }; DA20D84D2966A9B300F1581F /* CourseSearchVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseSearchVC.swift; sourceTree = ""; }; @@ -451,10 +452,10 @@ CE10063429680C0800FD31FB /* MyPageDto */ = { isa = PBXGroup; children = ( - CE10063D29680C8100FD31FB /* .gitkeep */, A3F67AE1296D33AC001598A2 /* MyPageDto.swift */, A3F67AE9296E4936001598A2 /* ActivityRecordInfoDto.swift */, A3305A96296EF58C000B1A10 /* GoalRewardInfoDto.swift */, + CEFA9A2E29FC263700F2D0CF /* UserDeleteResponseDto.swift */, ); path = MyPageDto; sourceTree = ""; @@ -1375,6 +1376,7 @@ DAD5A3D8296C6D9600C8166B /* AdImageCollectionViewCell.swift in Sources */, CE18E890296C76C100FEB569 /* RNLocationModel.swift in Sources */, CE6655DC295D873500C64E12 /* UIButton+.swift in Sources */, + CEFA9A2F29FC263700F2D0CF /* UserDeleteResponseDto.swift in Sources */, CE21C02C299E601000F62AF5 /* ScrapRouter.swift in Sources */, A3D1A78029CF142E00DD54EC /* UserManager.swift in Sources */, A3D1A77929CF03D200DD54EC /* AuthRouter.swift in Sources */, diff --git a/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/.gitkeep b/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/UserDeleteResponseDto.swift b/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/UserDeleteResponseDto.swift new file mode 100644 index 00000000..54b30f12 --- /dev/null +++ b/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/UserDeleteResponseDto.swift @@ -0,0 +1,12 @@ +// +// UserDeleteResponseDto.swift +// Runnect-iOS +// +// Created by sejin on 2023/04/29. +// + +import Foundation + +struct UserDeleteResponseDto: Codable { + let deletedUserId: Int +} diff --git a/Runnect-iOS/Runnect-iOS/Network/Router/UserRouter.swift b/Runnect-iOS/Runnect-iOS/Network/Router/UserRouter.swift index b3bcce38..ba8ea315 100644 --- a/Runnect-iOS/Runnect-iOS/Network/Router/UserRouter.swift +++ b/Runnect-iOS/Runnect-iOS/Network/Router/UserRouter.swift @@ -12,6 +12,7 @@ import Moya enum UserRouter { case getMyPageInfo case updateUserNickname(nickname: String) + case deleteUser } extension UserRouter: TargetType { @@ -25,7 +26,7 @@ extension UserRouter: TargetType { var path: String { switch self { - case .getMyPageInfo, .updateUserNickname: + case .getMyPageInfo, .updateUserNickname, .deleteUser: return "/user" } } @@ -36,12 +37,14 @@ extension UserRouter: TargetType { return .get case .updateUserNickname: return .patch + case .deleteUser: + return .delete } } var task: Moya.Task { switch self { - case .getMyPageInfo: + case .getMyPageInfo, .deleteUser: return .requestPlain case .updateUserNickname(let nickname): return .requestParameters(parameters: ["nickname": nickname], encoding: JSONEncoding.default) diff --git a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/PersonalInfoVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/PersonalInfoVC.swift index 0d2f764f..91223e99 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/PersonalInfoVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/PersonalInfoVC.swift @@ -12,6 +12,10 @@ import Then final class PersonalInfoVC: UIViewController { + // MARK: - Properties + + private let userProvider = Providers.userProvider + // MARK: - UI Components private lazy var navibar = CustomNavigationBar(self, type: .titleWithLeftButton).setTitle("계정 정보") @@ -106,7 +110,10 @@ extension PersonalInfoVC { } private func pushToDeleteAccountVC() { - let deleteAccountVC = DeleteAccountVC() + let deleteAccountVC = RNAlertVC(description: "정말로 탈퇴하시겠어요?") + deleteAccountVC.rightButtonTapAction = { [weak self] in + self?.deleteUser() + } deleteAccountVC.modalPresentationStyle = .overFullScreen self.present(deleteAccountVC, animated: false) } @@ -116,6 +123,10 @@ extension PersonalInfoVC { self.showSplashVC() } + private func deleteUserDidComplete() { + self.logout() + } + private func showSplashVC() { let splashVC = SplashVC() let navigationController = UINavigationController(rootViewController: splashVC) @@ -222,3 +233,36 @@ extension PersonalInfoVC { } } } + +// MARK: - Network + +extension PersonalInfoVC { + private func deleteUser() { + LoadingIndicator.showLoading() + self.userProvider.request(.deleteUser) { [weak self] result in + LoadingIndicator.hideLoading() + guard let self = self else { return } + switch result { + case .success(let response): + let status = response.statusCode + if 200..<300 ~= status { + do { + let responseDto = try response.map(BaseResponse.self) + guard let data = responseDto.data else { return } + print("삭제된 유저 아이디: \(data.deletedUserId)") + self.deleteUserDidComplete() + } catch { + print(error.localizedDescription) + } + } + if status >= 400 { + print("400 error") + self.showNetworkFailureToast() + } + case .failure(let error): + print(error) + self.showNetworkFailureToast() + } + } + } +}