Skip to content

Commit

Permalink
Merge pull request #98 from pknu-wap/feature/jaino/#87
Browse files Browse the repository at this point in the history
Feature/jaino/#87
  • Loading branch information
jeongjaino authored Jan 12, 2024
2 parents a90fafe + 53dc61e commit aa06536
Show file tree
Hide file tree
Showing 22 changed files with 186 additions and 71 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions app/src/main/java/com/wap/wapp/navigation/WappNavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ fun WappNavHost(
},
)
},
navigateToNotice = {
navController.navigateToNotice(
navOptions {
popUpTo(splashNavigationRoute) { inclusive = true }
},
)
},
)
signInScreen(
signInUseCase = signInUseCase,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.wap.wapp.core.data.di

import com.wap.wapp.core.data.repository.auth.AuthRepository
import com.wap.wapp.core.data.repository.auth.AuthRepositoryImpl
import com.wap.wapp.core.data.repository.event.EventRepository
import com.wap.wapp.core.data.repository.event.EventRepositoryImpl
import com.wap.wapp.core.data.repository.management.ManagementRepository
Expand All @@ -19,6 +21,12 @@ import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
abstract class DataModule {
@Binds
@Singleton
abstract fun bindsAuthRepository(
authRepositoryImpl: AuthRepositoryImpl,
): AuthRepository

@Binds
@Singleton
abstract fun bindsUserRepository(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.wap.wapp.core.data.di

import com.wap.wapp.core.data.repository.auth.AuthRepository
import com.wap.wapp.core.data.repository.auth.AuthRepositoryImpl
import com.wap.wapp.core.data.repository.auth.SignInRepository
import com.wap.wapp.core.data.repository.auth.SignInRepositoryImpl
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand All @@ -10,10 +10,10 @@ import dagger.hilt.android.scopes.ActivityScoped

@Module
@InstallIn(ActivityComponent::class)
abstract class AuthRepositoryModule {
abstract class SignInRepositoryModule {
@Binds
@ActivityScoped
abstract fun bindsAuthRepository(
authRepositoryImpl: AuthRepositoryImpl,
): AuthRepository
signInRepositoryImpl: SignInRepositoryImpl,
): SignInRepository
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.wap.wapp.core.data.repository.auth

interface AuthRepository {
suspend fun hasPendingResult(): Boolean

suspend fun signIn(email: String): Result<String>

suspend fun signOut(): Result<Unit>

suspend fun deleteUser(): Result<Unit>

suspend fun isUserSignIn(): Result<Boolean>
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import javax.inject.Inject
class AuthRepositoryImpl @Inject constructor(
private val authDataSource: AuthDataSource,
) : AuthRepository {
override suspend fun hasPendingResult(): Boolean = authDataSource.hasPendingResult()

override suspend fun signIn(email: String): Result<String> = authDataSource.signIn(email)

override suspend fun signOut(): Result<Unit> = authDataSource.signOut()

override suspend fun deleteUser(): Result<Unit> = authDataSource.deleteUser()

override suspend fun isUserSignIn(): Result<Boolean> = authDataSource.isUserSignIn()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.wap.wapp.core.data.repository.auth

interface SignInRepository {
suspend fun signIn(email: String): Result<String>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.wap.wapp.core.data.repository.auth

import com.wap.wapp.core.network.source.auth.SignInDataSource
import javax.inject.Inject

class SignInRepositoryImpl @Inject constructor(
private val signInDataSource: SignInDataSource,
) : SignInRepository {
override suspend fun signIn(email: String): Result<String> = signInDataSource.signIn(email)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.wap.wapp.core.domain.usecase.auth

import com.wap.wapp.core.data.repository.auth.AuthRepository
import javax.inject.Inject

class IsUserSignInUseCase @Inject constructor(
private val authRepository: AuthRepository,
) {
suspend operator fun invoke(): Result<Boolean> = authRepository.isUserSignIn()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.wap.wapp.core.domain.usecase.auth

import com.wap.wapp.core.data.repository.auth.AuthRepository
import com.wap.wapp.core.data.repository.auth.SignInRepository
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
Expand All @@ -10,11 +10,11 @@ import javax.inject.Inject

@ActivityScoped
class SignInUseCase @Inject constructor(
private val authRepository: AuthRepository,
private val signInRepository: SignInRepository,
private val userRepository: UserRepository,
) {
suspend operator fun invoke(email: String): Result<AuthState> = runCatching {
val userId = authRepository.signIn(email)
val userId = signInRepository.signIn(email)
.getOrThrow()

userRepository.getUserProfile(userId)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.wap.wapp.core.network.di

import com.wap.wapp.core.network.source.auth.AuthDataSource
import com.wap.wapp.core.network.source.auth.AuthDataSourceImpl
import com.wap.wapp.core.network.source.event.EventDataSource
import com.wap.wapp.core.network.source.event.EventDataSourceImpl
import com.wap.wapp.core.network.source.management.ManagementDataSource
Expand All @@ -20,6 +22,12 @@ import javax.inject.Singleton
@InstallIn(SingletonComponent::class)
abstract class NetworkModule {

@Binds
@Singleton
abstract fun bindsAuthDataSource(
authDataSourceImpl: AuthDataSourceImpl,
): AuthDataSource

@Binds
@Singleton
abstract fun bindsUserDataSource(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.wap.wapp.core.network.di

import com.wap.wapp.core.network.source.auth.AuthDataSource
import com.wap.wapp.core.network.source.auth.AuthDataSourceImpl
import com.wap.wapp.core.network.source.auth.SignInDataSource
import com.wap.wapp.core.network.source.auth.SignInDataSourceImpl
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand All @@ -10,10 +10,10 @@ import dagger.hilt.android.scopes.ActivityScoped

@Module
@InstallIn(ActivityComponent::class)
abstract class AuthDataSourceModule {
abstract class SignInDataSourceModule {
@Binds
@ActivityScoped
abstract fun bindsAuthDataSource(
authDataSourceImpl: AuthDataSourceImpl,
): AuthDataSource
abstract fun bindsSignInDataSource(
signInDataSourceImpl: SignInDataSourceImpl,
): SignInDataSource
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.wap.wapp.core.network.source.auth

interface AuthDataSource {
suspend fun hasPendingResult(): Boolean

suspend fun signIn(email: String): Result<String>

suspend fun signOut(): Result<Unit>

suspend fun deleteUser(): Result<Unit>

suspend fun isUserSignIn(): Result<Boolean>
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,15 @@
package com.wap.wapp.core.network.source.auth

import android.app.Activity
import android.content.Context
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.OAuthProvider
import com.google.firebase.auth.FirebaseAuth.AuthStateListener
import com.wap.wapp.core.network.utils.await
import dagger.hilt.android.qualifiers.ActivityContext
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.suspendCancellableCoroutine
import javax.inject.Inject

class AuthDataSourceImpl @Inject constructor(
private val firebaseAuth: FirebaseAuth,
@ActivityContext private val context: Context,
) : AuthDataSource {
override suspend fun hasPendingResult(): Boolean {
return firebaseAuth.pendingAuthResult != null
}

override suspend fun signIn(email: String): Result<String> {
return runCatching {
val provider = OAuthProvider.newBuilder("github.com")
provider.addCustomParameter("login", email)

val activityContext = context as Activity

val result = firebaseAuth.startActivityForSignInWithProvider(
activityContext,
provider.build(),
).await()

val user = checkNotNull(result.user)
user.uid
}
}

override suspend fun signOut(): Result<Unit> {
return runCatching {
firebaseAuth.signOut()
Expand All @@ -47,4 +24,29 @@ class AuthDataSourceImpl @Inject constructor(
.await()
}
}

@OptIn(ExperimentalCoroutinesApi::class)
override suspend fun isUserSignIn(): Result<Boolean> = runCatching {
suspendCancellableCoroutine { cont ->
val authStateListener = object : AuthStateListener {
override fun onAuthStateChanged(remoteAuth: FirebaseAuth) {
val user = remoteAuth.currentUser
if (user != null) {
cont.resume(true, null)
} else {
cont.resume(false, null)
}

// 한 번 호출된 후에 Listener 삭제
firebaseAuth.removeAuthStateListener(this)
}
}

firebaseAuth.addAuthStateListener(authStateListener)

cont.invokeOnCancellation { // Coroutine이 취소되는 경우 리스너 삭제
firebaseAuth.removeAuthStateListener(authStateListener)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.wap.wapp.core.network.source.auth

interface SignInDataSource {
suspend fun signIn(email: String): Result<String>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.wap.wapp.core.network.source.auth

import android.app.Activity
import android.content.Context
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.OAuthProvider
import com.wap.wapp.core.network.utils.await
import dagger.hilt.android.qualifiers.ActivityContext
import javax.inject.Inject

class SignInDataSourceImpl @Inject constructor(
private val firebaseAuth: FirebaseAuth,
@ActivityContext private val context: Context,
) : SignInDataSource {
override suspend fun signIn(email: String): Result<String> =
runCatching {
val provider = OAuthProvider.newBuilder("github.com")
provider.addCustomParameter("login", email)

val activityContext = context as Activity

val result = firebaseAuth.startActivityForSignInWithProvider(
activityContext,
provider.build(),
).await()

val user = checkNotNull(result.user)
user.uid
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class SurveyFormEditViewModel @Inject constructor(
_surveyQuestionList.value.addAll(surveyQuestionList)
}

private fun clearSurveyQuestionState() { _surveyQuestion.value = EMPTY }
private fun clearSurveyQuestionState() { _surveyQuestion.value = "" }

private fun isNotValidSurveyQuestion() = _surveyQuestion.value.isBlank()

Expand All @@ -221,8 +221,6 @@ class SurveyFormEditViewModel @Inject constructor(
}

companion object {
const val EMPTY = ""
val EVENT_SELECTION_INIT: Event =
Event("", "", "", "", DateUtil.generateNowDateTime(), DateUtil.generateNowDateTime())
val EVENT_SELECTION_INIT = Event("", "", "", "", LocalDateTime.MIN, LocalDateTime.MAX)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.LocalTime
import javax.inject.Inject

Expand Down Expand Up @@ -148,7 +149,7 @@ class SurveyFormRegistrationViewModel @Inject constructor(
clearSurveyQuestionState()
}

private fun clearSurveyQuestionState() { _surveyQuestion.value = EMPTY }
private fun clearSurveyQuestionState() { _surveyQuestion.value = "" }

private fun isNotValidSurveyQuestion() = _surveyQuestion.value.isBlank()

Expand Down Expand Up @@ -181,8 +182,6 @@ class SurveyFormRegistrationViewModel @Inject constructor(
}

companion object {
const val EMPTY = ""
val EVENT_SELECTION_INIT: Event =
Event("", "", "", "", DateUtil.generateNowDateTime(), DateUtil.generateNowDateTime())
val EVENT_SELECTION_INIT = Event("", "", "", "", LocalDateTime.MIN, LocalDateTime.MAX)
}
}
2 changes: 2 additions & 0 deletions feature/splash/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ dependencies {
implementation(project(":core:designresource"))
implementation(project(":core:designsystem"))
implementation(project(":core:common"))
implementation(project(":core:domain"))
implementation(project(":core:model"))

implementation(libs.bundles.androidx)
implementation(libs.material)
Expand Down
Loading

0 comments on commit aa06536

Please sign in to comment.