From da9b22ca055dda7725e38ff0101d63a2b5835b92 Mon Sep 17 00:00:00 2001 From: FreeDeveloper97 Date: Sun, 29 Sep 2024 18:42:28 +0900 Subject: [PATCH] =?UTF-8?q?feat=20#165=20postAuthCodeUseCase=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1,=20API=20=EC=9A=94=EC=B2=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project_Timer.xcodeproj/project.pbxproj | 12 +++++++ .../UseCase/AuthV2/PostAuthCodeUseCase.swift | 34 +++++++++++++++++++ .../Signin/LoginSelect/SigninSelectView.swift | 12 ++++--- .../Present/Signin/LoginView/SigninView.swift | 12 ++++--- .../Signup/Email/SignupEmailModel.swift | 34 +++++++++++++++---- .../Signup/Email/SignupEmailView.swift | 12 ++++--- 6 files changed, 98 insertions(+), 18 deletions(-) create mode 100644 Project_Timer/Domain/UseCase/AuthV2/PostAuthCodeUseCase.swift diff --git a/Project_Timer.xcodeproj/project.pbxproj b/Project_Timer.xcodeproj/project.pbxproj index de542a30..9fcf86de 100644 --- a/Project_Timer.xcodeproj/project.pbxproj +++ b/Project_Timer.xcodeproj/project.pbxproj @@ -134,6 +134,7 @@ 8736B7492CA94EBE006BD389 /* PostAuthCodeRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8736B7482CA94EBE006BD389 /* PostAuthCodeRequest.swift */; }; 8736B74B2CA94FC9006BD389 /* PostAuthCodeResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8736B74A2CA94FC9006BD389 /* PostAuthCodeResponse.swift */; }; 8736B74D2CA950D4006BD389 /* PostAuthCodeInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8736B74C2CA950D4006BD389 /* PostAuthCodeInfo.swift */; }; + 8736B7502CA951EC006BD389 /* PostAuthCodeUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8736B74F2CA951EC006BD389 /* PostAuthCodeUseCase.swift */; }; 873731D52B2E938400D7BD9F /* NotificationResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 873731D42B2E938400D7BD9F /* NotificationResponse.swift */; }; 873731DD2B2E9AA900D7BD9F /* FirebaseStringArrayValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 873731DC2B2E9AA900D7BD9F /* FirebaseStringArrayValue.swift */; }; 873731DF2B2EA2B000D7BD9F /* FirestoreValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 873731DE2B2EA2AF00D7BD9F /* FirestoreValue.swift */; }; @@ -566,6 +567,7 @@ 8736B7482CA94EBE006BD389 /* PostAuthCodeRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostAuthCodeRequest.swift; sourceTree = ""; }; 8736B74A2CA94FC9006BD389 /* PostAuthCodeResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostAuthCodeResponse.swift; sourceTree = ""; }; 8736B74C2CA950D4006BD389 /* PostAuthCodeInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostAuthCodeInfo.swift; sourceTree = ""; }; + 8736B74F2CA951EC006BD389 /* PostAuthCodeUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostAuthCodeUseCase.swift; sourceTree = ""; }; 873731D42B2E938400D7BD9F /* NotificationResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationResponse.swift; sourceTree = ""; }; 873731DC2B2E9AA900D7BD9F /* FirebaseStringArrayValue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirebaseStringArrayValue.swift; sourceTree = ""; }; 873731DE2B2EA2AF00D7BD9F /* FirestoreValue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirestoreValue.swift; sourceTree = ""; }; @@ -1153,6 +1155,14 @@ path = Resource; sourceTree = ""; }; + 8736B74E2CA951B6006BD389 /* AuthV2 */ = { + isa = PBXGroup; + children = ( + 8736B74F2CA951EC006BD389 /* PostAuthCodeUseCase.swift */, + ); + path = AuthV2; + sourceTree = ""; + }; 874A9DF42C6837BF006D2E19 /* Notification */ = { isa = PBXGroup; children = ( @@ -1958,6 +1968,7 @@ 871616922C3A146400C4EF25 /* Dailys */, 874A9DF52C68F279006D2E19 /* RecordTimes */, 874A9DF62C68F295006D2E19 /* SyncLog */, + 8736B74E2CA951B6006BD389 /* AuthV2 */, ); path = UseCase; sourceTree = ""; @@ -2528,6 +2539,7 @@ 8722104D2C2FFA66003B97AD /* TTResponse.swift in Sources */, 04573A992877FD78008F8D44 /* CountdownTimeLabelView.swift in Sources */, 87BEBEED281C282D0095CD29 /* Times.swift in Sources */, + 8736B7502CA951EC006BD389 /* PostAuthCodeUseCase.swift in Sources */, 879BE3222AC40444007AAC46 /* SignupSigninVM.swift in Sources */, 8791C1F627DCE703000D6BA9 /* UIView+Extension.swift in Sources */, 87D4DCC92BA52FC800BB5AAB /* ResetPasswordNicknameRoute.swift in Sources */, diff --git a/Project_Timer/Domain/UseCase/AuthV2/PostAuthCodeUseCase.swift b/Project_Timer/Domain/UseCase/AuthV2/PostAuthCodeUseCase.swift new file mode 100644 index 00000000..1b212cf7 --- /dev/null +++ b/Project_Timer/Domain/UseCase/AuthV2/PostAuthCodeUseCase.swift @@ -0,0 +1,34 @@ +// +// PostAuthCodeUseCase.swift +// Project_Timer +// +// Created by Kang Minsang on 2024/09/29. +// Copyright © 2024 FDEE. All rights reserved. +// + +import Foundation +import Combine + +final class PostAuthCodeUseCase { + enum PostType { + case signup(email: String) + } + + private let repository: AuthV2Repository // TODO: 프로토콜로 수정 + + init(repository: AuthV2Repository) { + self.repository = repository + } + + func execute(type: PostType) -> AnyPublisher { + switch type { + case .signup(let email): + return self.repository.postAuthcode( + request: PostAuthCodeRequest( + targetType: "EMAIL", + targetValue: email, + authType: "SIGN_UP") + ) + } + } +} diff --git a/Project_Timer/Present/Signin/LoginSelect/SigninSelectView.swift b/Project_Timer/Present/Signin/LoginSelect/SigninSelectView.swift index 1f05a951..4cfe406a 100644 --- a/Project_Timer/Present/Signin/LoginSelect/SigninSelectView.swift +++ b/Project_Timer/Present/Signin/LoginSelect/SigninSelectView.swift @@ -43,13 +43,17 @@ struct SigninSelectView: View { case .signupEmail: let infos = model.signupInfosForEmail // TODO: DI 수정 - let api = TTProvider(session: Session(interceptor: NetworkInterceptor.shared)) - let repository = UserRepository(api: api) - let getUsernameNotExistUseCase = GetUsernameNotExistUseCase(repository: repository) + let userApi = TTProvider(session: Session(interceptor: NetworkInterceptor.shared)) + let authApi = TTProvider(session: Session(interceptor: NetworkInterceptor.shared)) + let userRepository = UserRepository(api: userApi) + let authRepository = AuthV2Repository(api: authApi) + let getUsernameNotExistUseCase = GetUsernameNotExistUseCase(repository: userRepository) + let postAuthCodeUseCase = PostAuthCodeUseCase(repository: authRepository) SignupEmailView( model: SignupEmailModel( infos: infos, - getUsernameNotExistUseCase: getUsernameNotExistUseCase + getUsernameNotExistUseCase: getUsernameNotExistUseCase, + postAuthCodeUseCase: postAuthCodeUseCase ) ) case .signin: diff --git a/Project_Timer/Present/Signin/LoginView/SigninView.swift b/Project_Timer/Present/Signin/LoginView/SigninView.swift index 24575a31..a91766b8 100644 --- a/Project_Timer/Present/Signin/LoginView/SigninView.swift +++ b/Project_Timer/Present/Signin/LoginView/SigninView.swift @@ -42,13 +42,17 @@ struct SigninView: View { case .signup: let infos = SignupInfosForEmail(type: .normal, venderInfo: nil) // TODO: DI 수정 - let api = TTProvider(session: Session(interceptor: NetworkInterceptor.shared)) - let repository = UserRepository(api: api) - let getUsernameNotExistUseCase = GetUsernameNotExistUseCase(repository: repository) + let userApi = TTProvider(session: Session(interceptor: NetworkInterceptor.shared)) + let authApi = TTProvider(session: Session(interceptor: NetworkInterceptor.shared)) + let userRepository = UserRepository(api: userApi) + let authRepository = AuthV2Repository(api: authApi) + let getUsernameNotExistUseCase = GetUsernameNotExistUseCase(repository: userRepository) + let postAuthCodeUseCase = PostAuthCodeUseCase(repository: authRepository) SignupEmailView( model: SignupEmailModel( infos: infos, - getUsernameNotExistUseCase: getUsernameNotExistUseCase + getUsernameNotExistUseCase: getUsernameNotExistUseCase, + postAuthCodeUseCase: postAuthCodeUseCase ) ) } diff --git a/Project_Timer/Present/Signup/Email/SignupEmailModel.swift b/Project_Timer/Present/Signup/Email/SignupEmailModel.swift index 497881df..9f2160ab 100644 --- a/Project_Timer/Present/Signup/Email/SignupEmailModel.swift +++ b/Project_Timer/Present/Signup/Email/SignupEmailModel.swift @@ -55,11 +55,17 @@ class SignupEmailModel: ObservableObject { private var verificationKey = "" private let getUsernameNotExistUseCase: GetUsernameNotExistUseCase + private let postAuthCodeUseCase: PostAuthCodeUseCase private var cancellables = Set() - init(infos: SignupInfosForEmail, getUsernameNotExistUseCase: GetUsernameNotExistUseCase) { + init( + infos: SignupInfosForEmail, + getUsernameNotExistUseCase: GetUsernameNotExistUseCase, + postAuthCodeUseCase: PostAuthCodeUseCase + ) { self.infos = infos self.getUsernameNotExistUseCase = getUsernameNotExistUseCase + self.postAuthCodeUseCase = postAuthCodeUseCase // vender email 정보를 기본값으로 설정 if let email = infos.venderInfo?.email { self.email = email @@ -147,8 +153,9 @@ extension SignupEmailModel { self?.handleCheckEmailError(networkError) } receiveValue: { [weak self] checkUsernameInfo in if checkUsernameInfo.isNotExist { + // 성공, valid 단계 self?.emailStatus = .notExist - self?.resetVerificationCode() + self?.postAuthCode() } else { print("DetailInfo", #function, checkUsernameInfo.detailInfo) self?.emailStatus = .exist @@ -161,6 +168,20 @@ extension SignupEmailModel { } } + /// 인증코드 전송 + private func postAuthCode() { + self.postAuthCodeUseCase.execute(type: .signup(email: self.email)) + .sink { [weak self] completion in + guard case .failure(let networkError) = completion else { return } + print("ERROR", #function) + self?.handleCheckEmailError(networkError) + } receiveValue: { [weak self] postAuthCodeInfo in + print("authKey: \(postAuthCodeInfo.authKey)") + self?.resetVerificationCode() + } + .store(in: &self.cancellables) + } + // 인증코드 done 액션 func checkVerificationCode() { validVerificationCode = verificationCode.count > 7 @@ -175,18 +196,19 @@ extension SignupEmailModel { } private func resetEmail() { - validVerificationCode = nil - stage = .email + self.validVerificationCode = nil + self.stage = .email } private func resetVerificationCode() { - verificationCode = "" - stage = .verificationCode + self.verificationCode = "" + self.stage = .verificationCode } } extension SignupEmailModel { private func handleCheckEmailError(_ networkError: NetworkError) { + // TODO: 서버 문제, 요청 문제 등 분기처리 필요 self.emailStatus = .networkError guard case .ERRORRESPONSE(let ttErrorResponse) = networkError else { return } print(ttErrorResponse.logMessage) diff --git a/Project_Timer/Present/Signup/Email/SignupEmailView.swift b/Project_Timer/Present/Signup/Email/SignupEmailView.swift index a1702e8d..6026b736 100644 --- a/Project_Timer/Present/Signup/Email/SignupEmailView.swift +++ b/Project_Timer/Present/Signup/Email/SignupEmailView.swift @@ -179,13 +179,17 @@ struct SignupEmailView_Previews: PreviewProvider { static var previews: some View { // TODO: DI 수정 - let api = TTProvider(session: Session(interceptor: NetworkInterceptor.shared)) - let repository = UserRepository(api: api) - let getUsernameNotExistUseCase = GetUsernameNotExistUseCase(repository: repository) + let userApi = TTProvider(session: Session(interceptor: NetworkInterceptor.shared)) + let authApi = TTProvider(session: Session(interceptor: NetworkInterceptor.shared)) + let userRepository = UserRepository(api: userApi) + let authRepository = AuthV2Repository(api: authApi) + let getUsernameNotExistUseCase = GetUsernameNotExistUseCase(repository: userRepository) + let postAuthCodeUseCase = PostAuthCodeUseCase(repository: authRepository) SignupEmailView( model: SignupEmailModel( infos: infos, - getUsernameNotExistUseCase: getUsernameNotExistUseCase + getUsernameNotExistUseCase: getUsernameNotExistUseCase, + postAuthCodeUseCase: postAuthCodeUseCase ) ).environmentObject(SigninSignupEnvironment()) }