From 53bc9a91d2cc6a3ce7041ef36f7a50b9ee8bdd68 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Tue, 10 Oct 2023 16:09:11 +0900 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20#15=20:=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=20=ED=9A=8C=EC=9B=90=EA=B0=80=EC=9E=85=20=EC=9C=A0?= =?UTF-8?q?=EC=8A=A4=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wapp/core/domain/auth/SignInUseCase.kt | 13 -------- .../core/domain/usecase/auth/SignInUseCase.kt | 33 +++++++++++++++++++ 2 files changed, 33 insertions(+), 13 deletions(-) delete mode 100644 core/domain/src/main/java/com/wap/wapp/core/domain/auth/SignInUseCase.kt create mode 100644 core/domain/src/main/java/com/wap/wapp/core/domain/usecase/auth/SignInUseCase.kt diff --git a/core/domain/src/main/java/com/wap/wapp/core/domain/auth/SignInUseCase.kt b/core/domain/src/main/java/com/wap/wapp/core/domain/auth/SignInUseCase.kt deleted file mode 100644 index 5677fe94..00000000 --- a/core/domain/src/main/java/com/wap/wapp/core/domain/auth/SignInUseCase.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.wap.wapp.core.domain.auth - -import com.wap.wapp.core.data.repository.auth.AuthRepository -import dagger.hilt.android.scopes.ActivityScoped -import javax.inject.Inject - -@ActivityScoped -class SignInUseCase @Inject constructor( - private val repository: AuthRepository, -) { - suspend operator fun invoke(email: String): Result = - repository.signIn(email) -} diff --git a/core/domain/src/main/java/com/wap/wapp/core/domain/usecase/auth/SignInUseCase.kt b/core/domain/src/main/java/com/wap/wapp/core/domain/usecase/auth/SignInUseCase.kt new file mode 100644 index 00000000..dd7eea6c --- /dev/null +++ b/core/domain/src/main/java/com/wap/wapp/core/domain/usecase/auth/SignInUseCase.kt @@ -0,0 +1,33 @@ +package com.wap.wapp.core.domain.usecase.auth + +import com.wap.wapp.core.data.repository.auth.AuthRepository +import com.wap.wapp.core.data.repository.user.UserRepository +import com.wap.wapp.core.domain.model.AuthState +import com.wap.wapp.core.domain.model.AuthState.SIGN_IN +import com.wap.wapp.core.domain.model.AuthState.SIGN_UP +import dagger.hilt.android.scopes.ActivityScoped +import javax.inject.Inject + +@ActivityScoped +class SignInUseCase @Inject constructor( + private val authRepository: AuthRepository, + private val userRepository: UserRepository, +) { + suspend operator fun invoke(email: String): Result { + return runCatching { + val userId = authRepository.signIn(email) + .getOrThrow() + + userRepository.getUserProfile(userId) + .onFailure { exception -> + // 만약 사용자를 찾을 수 없는 경우, 회원가입 + val userNotFoundException = IllegalStateException() + if (exception == userNotFoundException) { + return Result.success(SIGN_UP) + } + } + // 사용자를 찾은 경우, 로그인 + SIGN_IN + } + } +}