Skip to content

Commit

Permalink
refactor: fcm을 data layer에서 처리하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
re4rk committed Oct 6, 2023
1 parent e2c80e7 commit fafd695
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import com.festago.festago.data.service.UserRetrofitService
import com.festago.festago.data.util.runCatchingWithErrorHandler
import com.festago.festago.repository.AuthRepository
import com.festago.festago.repository.TokenRepository
import com.google.firebase.messaging.FirebaseMessaging
import com.kakao.sdk.user.UserApiClient
import kotlinx.coroutines.tasks.await
import javax.inject.Inject

class AuthDefaultRepository @Inject constructor(
private val userRetrofitService: UserRetrofitService,
private val tokenRepository: TokenRepository,
private val firebaseMessaging: FirebaseMessaging,
) : AuthRepository {

override val isSigned: Boolean
Expand All @@ -18,7 +21,8 @@ class AuthDefaultRepository @Inject constructor(
override val token: String?
get() = tokenRepository.token

override suspend fun signIn(socialType: String, token: String, fcmToken: String): Result<Unit> {
override suspend fun signIn(socialType: String, token: String): Result<Unit> {
val fcmToken = firebaseMessaging.token.await()
return tokenRepository.signIn(socialType, token, fcmToken)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@ import com.festago.festago.analytics.logNetworkFailure
import com.festago.festago.presentation.util.MutableSingleLiveData
import com.festago.festago.presentation.util.SingleLiveData
import com.festago.festago.repository.AuthRepository
import com.google.firebase.messaging.FirebaseMessaging
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.launch
import kotlinx.coroutines.tasks.await
import javax.inject.Inject

@HiltViewModel
class SignInViewModel @Inject constructor(
private val authRepository: AuthRepository,
private val firebaseMessaging: FirebaseMessaging,
private val analyticsHelper: AnalyticsHelper,
) : ViewModel() {

Expand All @@ -36,17 +33,13 @@ class SignInViewModel @Inject constructor(

fun signIn(token: String) {
viewModelScope.launch(exceptionHandler) {
val fcmToken = firebaseMessaging.token.await()
authRepository.signIn(
SOCIAL_TYPE_KAKAO,
token,
fcmToken,
).onSuccess {
_event.setValue(SignInEvent.SignInSuccess)
}.onFailure {
_event.setValue(SignInEvent.SignInFailure)
analyticsHelper.logNetworkFailure(KEY_SIGN_IN_LOG, it.message.toString())
}
authRepository.signIn(SOCIAL_TYPE_KAKAO, token)
.onSuccess {
_event.setValue(SignInEvent.SignInSuccess)
}.onFailure {
_event.setValue(SignInEvent.SignInFailure)
analyticsHelper.logNetworkFailure(KEY_SIGN_IN_LOG, it.message.toString())
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.festago.festago.repository
interface AuthRepository {
val isSigned: Boolean
val token: String?
suspend fun signIn(socialType: String, token: String, fcmToken: String): Result<Unit?>
suspend fun signIn(socialType: String, token: String): Result<Unit?>
suspend fun signOut(): Result<Unit>
suspend fun deleteAccount(): Result<Unit>
}

0 comments on commit fafd695

Please sign in to comment.