-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
734a5ab
commit 53bc9a9
Showing
2 changed files
with
33 additions
and
13 deletions.
There are no files selected for viewing
13 changes: 0 additions & 13 deletions
13
core/domain/src/main/java/com/wap/wapp/core/domain/auth/SignInUseCase.kt
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
core/domain/src/main/java/com/wap/wapp/core/domain/usecase/auth/SignInUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<AuthState> { | ||
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 | ||
} | ||
} | ||
} |