Skip to content

Commit

Permalink
Merge pull request #73 from TeamHY2/Feature/#70-Withdrawal
Browse files Browse the repository at this point in the history
[Feature] 회원탈퇴 API 연동 및 구현
  • Loading branch information
Seokki-Kwon authored Nov 10, 2024
2 parents 829f72b + b68495c commit 86caf07
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 20 deletions.
12 changes: 8 additions & 4 deletions HongikYeolgong2.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
4707230F2CBC1A9C0046469F /* LoginRequestDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4707230E2CBC1A9C0046469F /* LoginRequestDTO.swift */; };
470723112CBC1B0A0046469F /* LoginResponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 470723102CBC1B0A0046469F /* LoginResponseDTO.swift */; };
470723132CBC1BF10046469F /* BaseResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 470723122CBC1BF10046469F /* BaseResponse.swift */; };
470723182CBC29510046469F /* AuthenticationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 470723172CBC29510046469F /* AuthenticationService.swift */; };
470723182CBC29510046469F /* AppleLoginManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 470723172CBC29510046469F /* AppleLoginManager.swift */; };
471940C82CAFCB1B00426D30 /* SizeCheckModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 471940C72CAFCB1B00426D30 /* SizeCheckModifier.swift */; };
471940CB2CAFD9B700426D30 /* RankingCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 471940CA2CAFD9B700426D30 /* RankingCell.swift */; };
471940CD2CAFDAD700426D30 /* WeeklyRanking+Mock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 471940CC2CAFDAD700426D30 /* WeeklyRanking+Mock.swift */; };
Expand Down Expand Up @@ -51,6 +51,7 @@
4763FFBA2CB913FF00990336 /* UserDataInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4763FFB92CB913FF00990336 /* UserDataInteractor.swift */; };
4763FFBC2CB9228B00990336 /* AppEnviroment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4763FFBB2CB9228B00990336 /* AppEnviroment.swift */; };
476D26092CDDF2B6002FEF5C /* CalendarCountAllResponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 476D26072CDDF2B6002FEF5C /* CalendarCountAllResponseDTO.swift */; };
4774C7BB2CDF632300CDD479 /* WithdrawResponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4774C7BA2CDF632300CDD479 /* WithdrawResponseDTO.swift */; };
4780043C2CCA8E2900FFAF00 /* WeeklyStudyCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4780043B2CCA8E2900FFAF00 /* WeeklyStudyCell.swift */; };
478004422CCA924200FFAF00 /* StudySessionMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 478004412CCA924200FFAF00 /* StudySessionMapper.swift */; };
4780044C2CCAAD4F00FFAF00 /* WeekDay.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4780044B2CCAAD4F00FFAF00 /* WeekDay.swift */; };
Expand Down Expand Up @@ -175,7 +176,7 @@
470723102CBC1B0A0046469F /* LoginResponseDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginResponseDTO.swift; sourceTree = "<group>"; };
470723122CBC1BF10046469F /* BaseResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseResponse.swift; sourceTree = "<group>"; };
470723142CBC222E0046469F /* HongikYeolgong2.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = HongikYeolgong2.entitlements; sourceTree = "<group>"; };
470723172CBC29510046469F /* AuthenticationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticationService.swift; sourceTree = "<group>"; };
470723172CBC29510046469F /* AppleLoginManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleLoginManager.swift; sourceTree = "<group>"; };
471940C72CAFCB1B00426D30 /* SizeCheckModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SizeCheckModifier.swift; sourceTree = "<group>"; };
471940CA2CAFD9B700426D30 /* RankingCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RankingCell.swift; sourceTree = "<group>"; };
471940CC2CAFDAD700426D30 /* WeeklyRanking+Mock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WeeklyRanking+Mock.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -208,6 +209,7 @@
4763FFB92CB913FF00990336 /* UserDataInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDataInteractor.swift; sourceTree = "<group>"; };
4763FFBB2CB9228B00990336 /* AppEnviroment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppEnviroment.swift; sourceTree = "<group>"; };
476D26072CDDF2B6002FEF5C /* CalendarCountAllResponseDTO.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CalendarCountAllResponseDTO.swift; sourceTree = "<group>"; };
4774C7BA2CDF632300CDD479 /* WithdrawResponseDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WithdrawResponseDTO.swift; sourceTree = "<group>"; };
4780043B2CCA8E2900FFAF00 /* WeeklyStudyCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeeklyStudyCell.swift; sourceTree = "<group>"; };
478004412CCA924200FFAF00 /* StudySessionMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StudySessionMapper.swift; sourceTree = "<group>"; };
4780044B2CCAAD4F00FFAF00 /* WeekDay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeekDay.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -871,7 +873,7 @@
47F4F69E2CC8E45A00543D24 /* Services */ = {
isa = PBXGroup;
children = (
470723172CBC29510046469F /* AuthenticationService.swift */,
470723172CBC29510046469F /* AppleLoginManager.swift */,
47BE30E22CC813BB0015D973 /* KeyChainManager.swift */,
);
path = Services;
Expand All @@ -885,6 +887,7 @@
47F4F6962CC88FBB00543D24 /* SignUpRequestDTO.swift */,
47F4F6982CC89A6900543D24 /* SignUpResponseDTO.swift */,
470483A92CDB532A00C381ED /* TokenValidResponseDTO.swift */,
4774C7BA2CDF632300CDD479 /* WithdrawResponseDTO.swift */,
);
path = Auth;
sourceTree = "<group>";
Expand Down Expand Up @@ -1192,10 +1195,11 @@
478004422CCA924200FFAF00 /* StudySessionMapper.swift in Sources */,
478F84372CD30A8F0097CAA1 /* IOSBackground.swift in Sources */,
47A1474E2CA144EC00A91F66 /* StudyRoomUsage+Mock.swift in Sources */,
4774C7BB2CDF632300CDD479 /* WithdrawResponseDTO.swift in Sources */,
47D5EDCD2CCBCB6D00ACA469 /* ImageBackground.swift in Sources */,
473E8EB42CCE6827000F102C /* TimeInterval+.swift in Sources */,
4763FFB32CB90E3800990336 /* InteractorsContainer.swift in Sources */,
470723182CBC29510046469F /* AuthenticationService.swift in Sources */,
470723182CBC29510046469F /* AppleLoginManager.swift in Sources */,
5E847A6E2CDBD4B60034C2A7 /* CalendarView.swift in Sources */,
47BE30E32CC813BB0015D973 /* KeyChainManager.swift in Sources */,
4786A10C2CCA34A7008635A4 /* StudySessionRepositoryImpl.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion HongikYeolgong2/Core/AppEnviroment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@ extension DIContainer {
}

struct Services {
let appleAuthService: AuthenticationService
let appleAuthService: AppleLoginManager
}
}
15 changes: 15 additions & 0 deletions HongikYeolgong2/Data/DTO/Auth/WithdrawResponseDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// WithdrawResponseDTO.swift
// HongikYeolgong2
//
// Created by 권석기 on 11/9/24.
//

import Foundation

struct WithdrawResponseDTO: Decodable {
let id: Int
let username: String
let nickname: String
let department: String
}
16 changes: 16 additions & 0 deletions HongikYeolgong2/Data/Repositories/Auth/AuthRepositoryImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,20 @@ final class AuthRepositoryImpl: AuthRepository {
}
}.eraseToAnyPublisher()
}


func withdraw() -> AnyPublisher<Void, NetworkError> {
return Future<Void, NetworkError> { promise in
Task {
do {
let response: BaseResponse<WithdrawResponseDTO> = try await NetworkService.shared.request(endpoint: AuthEndpoint.withdraw)

promise(.success(()))
} catch let error as NetworkError {

promise(.failure(error))
}
}
}.eraseToAnyPublisher()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ final class UserDataMigrationInteractor: UserDataInteractor {
private let cancleBag = CancelBag()
private let appState: Store<AppState>
private let authRepository: AuthRepository
private let authService: AuthenticationService
private let authService: AppleLoginManager
private let db = Firestore.firestore()

init(appState: Store<AppState>,
authRepository: AuthRepository,
authService: AuthenticationService) {
authService: AppleLoginManager) {
self.appState = appState
self.authRepository = authRepository
self.authService = authService
Expand All @@ -50,7 +50,7 @@ final class UserDataMigrationInteractor: UserDataInteractor {
// credential로 로그인 요청
Auth.auth().signIn(with: credential) { [weak self] (result, error) in
guard let self = self,
let userId = result?.user.uid else { return }
let userId = result?.user.uid else { return }

let docRef = db.collection("User").document(userId)

Expand Down Expand Up @@ -170,6 +170,24 @@ final class UserDataMigrationInteractor: UserDataInteractor {
})
.store(in: cancleBag)
}

/// 회원탈퇴
func withdraw() {
authRepository
.withdraw()
.sink(receiveCompletion: { _ in }) { [weak self] in
guard let self = self else { return }
appState.bulkUpdate { appState in
appState.userSession = .unauthenticated
appState.userData = .init()
appState.permissions = .init()
appState.studySession = .init()
appState.system = .init()
}
KeyChainManager.deleteItem(key: .accessToken)
}
.store(in: cancleBag)
}
}

extension UserDataMigrationInteractor {
Expand Down
9 changes: 7 additions & 2 deletions HongikYeolgong2/Domain/Interactors/UserDataInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ protocol UserDataInteractor: AnyObject {
func getUser()
func checkAuthentication()
func checkUserNickname(nickname: String, nicknameCheckSubject: CurrentValueSubject<Bool, Never>)
func withdraw()
}

final class UserDataInteractorImpl: UserDataInteractor {

private let cancleBag = CancelBag()
private let appState: Store<AppState>
private let authRepository: AuthRepository
private let authService: AuthenticationService
private let authService: AppleLoginManager

init(appState: Store<AppState>,
authRepository: AuthRepository,
authService: AuthenticationService) {
authService: AppleLoginManager) {
self.appState = appState
self.authRepository = authRepository
self.authService = authService
Expand Down Expand Up @@ -146,4 +147,8 @@ final class UserDataInteractorImpl: UserDataInteractor {
})
.store(in: cancleBag)
}

func withdraw() {

}
}
1 change: 1 addition & 0 deletions HongikYeolgong2/Domain/Interfaces/AuthRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ protocol AuthRepository {
func checkUserNickname(nickname: String) -> AnyPublisher<Bool, NetworkError>
func getUser() -> AnyPublisher<SignUpResponseDTO, NetworkError>
func validToken() -> AnyPublisher<TokenValidResponseDTO, NetworkError>
func withdraw() -> AnyPublisher<Void, NetworkError>
}
6 changes: 3 additions & 3 deletions HongikYeolgong2/Presentation/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ struct HomeView: View {
ActionButtonControllerView(
studySession: $studySession,
actions: .init(
endButtonTapped: { shouldShowEndUseModal = true },
startButtonTapped: { shouldShowTimePicker = true },
endButtonTapped: { shouldShowEndUseModal.toggle() },
startButtonTapped: { shouldShowTimePicker.toggle() },
seatButtonTapped: {},
addButtonTapped: { shouldShowAddTimeModal = true }
addButtonTapped: { shouldShowAddTimeModal.toggle() }
)
)
}
Expand Down
17 changes: 14 additions & 3 deletions HongikYeolgong2/Presentation/Setting/SettingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import SwiftUI
struct SettingView: View {
@State private var isOnAlarm = false
@Environment(\.injected) var injected: DIContainer

@Environment(\.injected.interactors.userDataInteractor) var userDataInteractor

@State private var shouldShowWithdrawModal = false
var body: some View {
VStack(alignment:.leading, spacing: 0){
HStack(spacing: 0) {
Expand All @@ -13,7 +15,7 @@ struct SettingView: View {
Text("유림")
.font(.pretendard(size: 16, weight: .regular))
.padding(.trailing, 8)

.foregroundStyle(.gray200)
Text("|")
.font(.pretendard(size: 16, weight: .regular))
Expand Down Expand Up @@ -106,7 +108,7 @@ struct SettingView: View {
.padding(.horizontal, 24.adjustToScreenWidth)

Button(action: {

shouldShowWithdrawModal.toggle()
}, label: {
Text("회원탈퇴")
.font(.pretendard(size: 16, weight: .regular))
Expand All @@ -116,6 +118,15 @@ struct SettingView: View {
}
.padding(.bottom, 36.adjustToScreenHeight)
}
.systemOverlay(isPresented: $shouldShowWithdrawModal) {
ModalView(isPresented: $shouldShowWithdrawModal,
title: "정말 탈퇴하실 건가요?",
confirmButtonText: "돌아가기",
cancleButtonText: "탈퇴하기",
confirmAction: {},
cancleAction: { userDataInteractor.withdraw() }
)
}
.padding(.top, 16.5.adjustToScreenHeight)
.padding(.horizontal, 16.adjustToScreenWidth)
.background(.dark)
Expand Down
2 changes: 1 addition & 1 deletion HongikYeolgong2/Util/API/Base/NetworkService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct NetworkService: NetworkProtocol {

extension NetworkService {
private func configUrl(endpoint: EndpointProtocol) -> URL? {
guard let url = endpoint.baseURL?.appendingPathComponent(endpoint.path) else {
guard let url = endpoint.path.isEmpty ? endpoint.baseURL : endpoint.baseURL?.appendingPathComponent(endpoint.path) else {
return nil
}

Expand Down
11 changes: 11 additions & 0 deletions HongikYeolgong2/Util/API/Endpoints/AuthEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ enum AuthEndpoint: EndpointProtocol {

/// 애플 소셜 로그인
case login(loginReqDto: LoginRequestDTO)

/// 회원탈퇴
case withdraw
}

extension AuthEndpoint {
Expand All @@ -22,20 +25,26 @@ extension AuthEndpoint {
switch self {
case .login:
"/login-apple"
case .withdraw:
""
}
}

var method: NetworkMethod {
switch self {
case .login:
.post
case .withdraw:
.delete
}
}

var parameters: [URLQueryItem]? {
switch self {
case .login:
nil
default:
nil
}
}

Expand All @@ -50,6 +59,8 @@ extension AuthEndpoint {
switch self {
case let .login(loginReqDto):
return loginReqDto.toData()
default:
return nil
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import Foundation
import AuthenticationServices

protocol AuthenticationService {
protocol AppleLoginManager {
func requestAppleLogin(_ authrization: ASAuthorization) -> (email: String, idToken: String)?
}

final class AuthenticationServiceImpl: AuthenticationService {
final class AuthenticationServiceImpl: AppleLoginManager {

/// 애플로그인 요청을 위한 이메일과 토큰을 반환합니다.(이메일은 첫로그인시 반환)
/// - Parameter authorization: authorization
Expand Down
2 changes: 1 addition & 1 deletion HongikYeolgong2/Util/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extension Store {
var value = self.value
update(&value)
self.value = value
}
}

func updates<Value>(for keyPath: KeyPath<Output, Value>) ->
AnyPublisher<Value, Failure> where Value: Equatable {
Expand Down

0 comments on commit 86caf07

Please sign in to comment.