Skip to content

Commit

Permalink
feat #165 postAuthCodeUseCase 생성, API 요청
Browse files Browse the repository at this point in the history
  • Loading branch information
minsangKang committed Sep 29, 2024
1 parent 1461220 commit da9b22c
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 18 deletions.
12 changes: 12 additions & 0 deletions Project_Timer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -566,6 +567,7 @@
8736B7482CA94EBE006BD389 /* PostAuthCodeRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostAuthCodeRequest.swift; sourceTree = "<group>"; };
8736B74A2CA94FC9006BD389 /* PostAuthCodeResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostAuthCodeResponse.swift; sourceTree = "<group>"; };
8736B74C2CA950D4006BD389 /* PostAuthCodeInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostAuthCodeInfo.swift; sourceTree = "<group>"; };
8736B74F2CA951EC006BD389 /* PostAuthCodeUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostAuthCodeUseCase.swift; sourceTree = "<group>"; };
873731D42B2E938400D7BD9F /* NotificationResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationResponse.swift; sourceTree = "<group>"; };
873731DC2B2E9AA900D7BD9F /* FirebaseStringArrayValue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirebaseStringArrayValue.swift; sourceTree = "<group>"; };
873731DE2B2EA2AF00D7BD9F /* FirestoreValue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirestoreValue.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1153,6 +1155,14 @@
path = Resource;
sourceTree = "<group>";
};
8736B74E2CA951B6006BD389 /* AuthV2 */ = {
isa = PBXGroup;
children = (
8736B74F2CA951EC006BD389 /* PostAuthCodeUseCase.swift */,
);
path = AuthV2;
sourceTree = "<group>";
};
874A9DF42C6837BF006D2E19 /* Notification */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1958,6 +1968,7 @@
871616922C3A146400C4EF25 /* Dailys */,
874A9DF52C68F279006D2E19 /* RecordTimes */,
874A9DF62C68F295006D2E19 /* SyncLog */,
8736B74E2CA951B6006BD389 /* AuthV2 */,
);
path = UseCase;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
34 changes: 34 additions & 0 deletions Project_Timer/Domain/UseCase/AuthV2/PostAuthCodeUseCase.swift
Original file line number Diff line number Diff line change
@@ -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<PostAuthCodeInfo, NetworkError> {
switch type {
case .signup(let email):
return self.repository.postAuthcode(
request: PostAuthCodeRequest(
targetType: "EMAIL",
targetValue: email,
authType: "SIGN_UP")
)
}
}
}
12 changes: 8 additions & 4 deletions Project_Timer/Present/Signin/LoginSelect/SigninSelectView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ struct SigninSelectView: View {
case .signupEmail:
let infos = model.signupInfosForEmail
// TODO: DI 수정
let api = TTProvider<UserAPI>(session: Session(interceptor: NetworkInterceptor.shared))
let repository = UserRepository(api: api)
let getUsernameNotExistUseCase = GetUsernameNotExistUseCase(repository: repository)
let userApi = TTProvider<UserAPI>(session: Session(interceptor: NetworkInterceptor.shared))
let authApi = TTProvider<AuthV2API>(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:
Expand Down
12 changes: 8 additions & 4 deletions Project_Timer/Present/Signin/LoginView/SigninView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@ struct SigninView: View {
case .signup:
let infos = SignupInfosForEmail(type: .normal, venderInfo: nil)
// TODO: DI 수정
let api = TTProvider<UserAPI>(session: Session(interceptor: NetworkInterceptor.shared))
let repository = UserRepository(api: api)
let getUsernameNotExistUseCase = GetUsernameNotExistUseCase(repository: repository)
let userApi = TTProvider<UserAPI>(session: Session(interceptor: NetworkInterceptor.shared))
let authApi = TTProvider<AuthV2API>(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
)
)
}
Expand Down
34 changes: 28 additions & 6 deletions Project_Timer/Present/Signup/Email/SignupEmailModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,17 @@ class SignupEmailModel: ObservableObject {
private var verificationKey = ""

private let getUsernameNotExistUseCase: GetUsernameNotExistUseCase
private let postAuthCodeUseCase: PostAuthCodeUseCase
private var cancellables = Set<AnyCancellable>()

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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions Project_Timer/Present/Signup/Email/SignupEmailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,17 @@ struct SignupEmailView_Previews: PreviewProvider {

static var previews: some View {
// TODO: DI 수정
let api = TTProvider<UserAPI>(session: Session(interceptor: NetworkInterceptor.shared))
let repository = UserRepository(api: api)
let getUsernameNotExistUseCase = GetUsernameNotExistUseCase(repository: repository)
let userApi = TTProvider<UserAPI>(session: Session(interceptor: NetworkInterceptor.shared))
let authApi = TTProvider<AuthV2API>(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())
}
Expand Down

0 comments on commit da9b22c

Please sign in to comment.