Skip to content

Commit

Permalink
[FEAT/#40] dataStore UseCase 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
gaeun5744 committed Sep 26, 2023
1 parent d58bfa7 commit 9a70255
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.puzzling.puzzlingaos.domain.usecase.onboarding

import com.puzzling.puzzlingaos.domain.repository.TokenRepository
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class GetTokenUseCase @Inject constructor(
private val tokenRepository: TokenRepository,
) {

suspend operator fun invoke() = tokenRepository.getToken()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.puzzling.puzzlingaos.domain.usecase.onboarding

import com.puzzling.puzzlingaos.domain.repository.TokenRepository
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class PostTokenUseCase @Inject constructor(private val tokenRepository: TokenRepository) {
suspend operator fun invoke(token: String) = tokenRepository.setToken(token)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@ package com.puzzling.puzzlingaos.presentation.onboarding

import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.kakao.sdk.auth.model.OAuthToken
import com.puzzling.puzzlingaos.data.datasource.local.LocalDataSource
import com.puzzling.puzzlingaos.domain.usecase.onboarding.GetTokenUseCase
import com.puzzling.puzzlingaos.domain.usecase.onboarding.PostTokenUseCase
import com.puzzling.puzzlingaos.util.KakaoLoginCallback
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class LoginViewModel @Inject constructor() :
class LoginViewModel @Inject constructor(
private val postTokenUseCase: PostTokenUseCase,
private val getTokenUseCase: GetTokenUseCase,
) :
ViewModel() {
private val _isKakaoLogin = MutableStateFlow(false)
val isKakaoLogin = _isKakaoLogin.asStateFlow()
Expand All @@ -21,6 +28,10 @@ class LoginViewModel @Inject constructor() :
_isKakaoLogin.value = true
Log.d("LoginViewModel", "토큰!! $token")
LocalDataSource.setAccessToken("$token")
viewModelScope.launch {
postTokenUseCase.invoke(it)
Log.d("LoginViewModel", "토큰!! usecase ${getTokenUseCase.invoke()}")
}
}.handleResult(token, error)
}
}

0 comments on commit 9a70255

Please sign in to comment.