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 + } + } +}