Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

구글 로그인 Request 모델 수정 #20

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package com.goalpanzi.mission_mate.core.data.repository
import com.goalpanzi.mission_mate.core.domain.repository.LoginRepository
import com.goalpanzi.mission_mate.core.network.service.LoginService
import com.luckyoct.core.model.GoogleLogin
import com.luckyoct.core.model.base.NetworkResult
import com.luckyoct.core.model.request.GoogleLoginRequest
import javax.inject.Inject

class LoginRepositoryImpl @Inject constructor(
private val loginService: LoginService
): LoginRepository {

override suspend fun requestGoogleLogin(token: String, email: String): GoogleLogin {
val request = GoogleLoginRequest(identityToken = token, email = email)
val response = loginService.requestGoogleLogin(request)
return response
override suspend fun requestGoogleLogin(email: String) = handleResult {
val request = GoogleLoginRequest(email = email)
loginService.requestGoogleLogin(request)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.goalpanzi.mission_mate.core.domain.repository

import com.goalpanzi.mission_mate.core.network.ResultHandler
import com.luckyoct.core.model.GoogleLogin
import com.luckyoct.core.model.base.NetworkResult

interface LoginRepository {
suspend fun requestGoogleLogin(token: String, email: String): GoogleLogin
interface LoginRepository : ResultHandler {
suspend fun requestGoogleLogin(email: String): NetworkResult<GoogleLogin>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@ package com.goalpanzi.mission_mate.core.domain.usecase
import com.goalpanzi.mission_mate.core.datastore.datasource.AuthDataSource
import com.goalpanzi.mission_mate.core.domain.repository.LoginRepository
import com.luckyoct.core.model.GoogleLogin
import com.luckyoct.core.model.base.NetworkResult
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

class LoginUseCase @Inject constructor(
private val loginRepository: LoginRepository,
private val authDataSource: AuthDataSource
) {

suspend fun requestGoogleLogin(token: String, email: String): GoogleLogin {
val response = loginRepository.requestGoogleLogin(token, email)
authDataSource.setAccessToken(response.accessToken).first()
authDataSource.setRefreshToken(response.refreshToken).first()
return response
suspend fun requestGoogleLogin(email: String): GoogleLogin? {
return when (val response = loginRepository.requestGoogleLogin(email)) {
is NetworkResult.Success -> {
response.data.also {
authDataSource.setAccessToken(it.accessToken).first()
authDataSource.setRefreshToken(it.refreshToken).first()
}
}
is NetworkResult.Error, is NetworkResult.Exception -> null
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ import kotlinx.serialization.Serializable

@Serializable
data class GoogleLoginRequest(
val identityToken: String,
val email: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.goalpanzi.mission_mate.core.network.service

import com.luckyoct.core.model.GoogleLogin
import com.luckyoct.core.model.request.GoogleLoginRequest
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.POST

Expand All @@ -10,5 +11,5 @@ interface LoginService {
@POST("/api/auth/login/google")
suspend fun requestGoogleLogin(
@Body request: GoogleLoginRequest
): GoogleLogin
): Response<GoogleLogin>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package com.goalpanzi.mission_mate.feature.login

sealed interface LoginEvent {
data object Error : LoginEvent
data class Success(val isAlreadyMember: Boolean) : LoginEvent
data class Success(val isProfileSet: Boolean) : LoginEvent
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fun LoginRoute(
viewModel.eventFlow.collectLatest {
when (it) {
LoginEvent.Error -> Unit
is LoginEvent.Success -> onLoginSuccess(it.isAlreadyMember)
is LoginEvent.Success -> onLoginSuccess(it.isProfileSet)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.credentials.GetCredentialResponse
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.goalpanzi.mission_mate.core.domain.usecase.LoginUseCase
import com.goalpanzi.mission_mate.feature.login.util.TokenUtil
import com.google.android.libraries.identity.googleid.GetSignInWithGoogleOption
import com.google.android.libraries.identity.googleid.GoogleIdTokenCredential
import com.google.android.libraries.identity.googleid.GoogleIdTokenParsingException
Expand Down Expand Up @@ -51,14 +50,15 @@ class LoginViewModel @Inject constructor(
is CustomCredential -> {
if (credential.type == GoogleIdTokenCredential.TYPE_GOOGLE_ID_TOKEN_CREDENTIAL) {
try {
val googleIdTokenCredential =
GoogleIdTokenCredential.createFrom(credential.data)
val compressedToken = TokenUtil.compressToken(googleIdTokenCredential.idToken)
val result = loginUseCase.requestGoogleLogin(
token = compressedToken,
email = googleIdTokenCredential.id
val googleIdTokenCredential = GoogleIdTokenCredential.createFrom(credential.data)
val result = loginUseCase.requestGoogleLogin(email = googleIdTokenCredential.id)
_eventFlow.emit(
result?.let {
LoginEvent.Success(it.isProfileSet)
} ?: run {
LoginEvent.Error
}
)
_eventFlow.emit(LoginEvent.Success(result.isProfileSet))
} catch (e: GoogleIdTokenParsingException) {
e.printStackTrace()
}
Expand Down

This file was deleted.

Loading