Skip to content

Commit

Permalink
[Feat] Runnect#129 - 회원 탈퇴 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
lsj8706 committed Apr 28, 2023
1 parent 424cfa0 commit 0777c9b
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 5 deletions.
6 changes: 4 additions & 2 deletions Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -186,7 +187,6 @@
CE0C23782966D6AF00B45063 /* ViewPager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewPager.swift; sourceTree = "<group>"; };
CE0D9FD229648DA300CEB5CD /* CustomAlertVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomAlertVC.swift; sourceTree = "<group>"; };
CE10063929680C5700FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = "<group>"; };
CE10063D29680C8100FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = "<group>"; };
CE10064D29680D2500FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = "<group>"; };
CE10064F29680D3300FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = "<group>"; };
CE10065029680D3800FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = "<group>"; };
Expand Down Expand Up @@ -308,6 +308,7 @@
CEEC6B482961C5E200D00E1E /* SplashVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashVC.swift; sourceTree = "<group>"; };
CEEC6B4A2961D89700D00E1E /* CustomNavigationBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomNavigationBar.swift; sourceTree = "<group>"; };
CEF3CD99296DB305002723A1 /* CourseDetailResponseDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseDetailResponseDto.swift; sourceTree = "<group>"; };
CEFA9A2E29FC263700F2D0CF /* UserDeleteResponseDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDeleteResponseDto.swift; sourceTree = "<group>"; };
DA20D846296697A600F1581F /* MyCourseSelectVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyCourseSelectVC.swift; sourceTree = "<group>"; };
DA20D848296697B400F1581F /* CourseUploadVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseUploadVC.swift; sourceTree = "<group>"; };
DA20D84D2966A9B300F1581F /* CourseSearchVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseSearchVC.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// UserDeleteResponseDto.swift
// Runnect-iOS
//
// Created by sejin on 2023/04/29.
//

import Foundation

struct UserDeleteResponseDto: Codable {
let deletedUserId: Int
}
7 changes: 5 additions & 2 deletions Runnect-iOS/Runnect-iOS/Network/Router/UserRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Moya
enum UserRouter {
case getMyPageInfo
case updateUserNickname(nickname: String)
case deleteUser
}

extension UserRouter: TargetType {
Expand All @@ -25,7 +26,7 @@ extension UserRouter: TargetType {

var path: String {
switch self {
case .getMyPageInfo, .updateUserNickname:
case .getMyPageInfo, .updateUserNickname, .deleteUser:
return "/user"
}
}
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("계정 정보")
Expand Down Expand Up @@ -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)
}
Expand All @@ -116,6 +123,10 @@ extension PersonalInfoVC {
self.showSplashVC()
}

private func deleteUserDidComplete() {
self.logout()
}

private func showSplashVC() {
let splashVC = SplashVC()
let navigationController = UINavigationController(rootViewController: splashVC)
Expand Down Expand Up @@ -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<UserDeleteResponseDto>.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()
}
}
}
}

0 comments on commit 0777c9b

Please sign in to comment.