Skip to content

Commit

Permalink
Merge pull request #20 from Nexters/feature/fix-google-login-request
Browse files Browse the repository at this point in the history
구글 로그인 Request 모델 수정
  • Loading branch information
bywindow authored Aug 6, 2024
2 parents 37f768a + 96470e3 commit 218549b
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 34 deletions.
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.

0 comments on commit 218549b

Please sign in to comment.