Skip to content

Commit

Permalink
[FEAT/#41] SignIn model 생성 및 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
chattymin committed Jan 9, 2024
1 parent f0152ac commit 837d0b2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.going.data.dto.request

import com.going.domain.entity.request.RequestSignInModel
import com.going.domain.entity.request.RequestSignUpModel
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand All @@ -8,3 +10,6 @@ data class SignInRequestDto(
@SerialName("platform")
val platform: String
)

fun RequestSignInModel.toSignInRequestDto(): SignInRequestDto =
SignInRequestDto(platform)
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.going.data.repositoryImpl

import com.going.data.datasource.AuthDataSource
import com.going.data.dto.request.SignInRequestDto
import com.going.data.dto.request.toSignInRequestDto
import com.going.data.dto.request.toSignUpRequestDto
import com.going.domain.entity.request.RequestSignInModel
import com.going.domain.entity.request.RequestSignUpModel
import com.going.domain.entity.response.AuthTokenModel
import com.going.domain.repository.AuthRepository
Expand All @@ -13,12 +14,12 @@ class AuthRepositoryImpl @Inject constructor(
) : AuthRepository {
override suspend fun postSignIn(
Authorization: String,
platform: String,
data: RequestSignInModel,
): Result<AuthTokenModel> =
runCatching {
authDataSource.postLogin(
Authorization,
SignInRequestDto(platform),
data.toSignInRequestDto(),
).data.toAuthTokenModel()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.going.domain.entity.request

data class RequestSignInModel(
val platform: String
)
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.going.domain.repository

import com.going.domain.entity.request.RequestSignInModel
import com.going.domain.entity.request.RequestSignUpModel
import com.going.domain.entity.response.AuthTokenModel

interface AuthRepository {
suspend fun postSignIn(
Authorization: String,
platform: String,
data: RequestSignInModel,
): Result<AuthTokenModel>

suspend fun postSignUp(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.going.presentation.onboarding.signin
import android.content.Context
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.going.domain.entity.request.RequestSignInModel
import com.going.domain.repository.AuthRepository
import com.going.domain.repository.TokenRepository
import com.going.presentation.util.toErrorCode
Expand Down Expand Up @@ -65,12 +66,12 @@ class SignInViewModel @Inject constructor(
// 서버통신 - 카카오 토큰 보내서 서비스 토큰 받아오기 - 서버와 협의 후 수정예정
private fun changeTokenFromServer(
accessToken: String,
social: String = KAKAO,
platform: String = KAKAO,
) {
_postChangeTokenState.value = SignInState.LOADING

viewModelScope.launch {
authRepository.postSignIn(accessToken, social).onSuccess {
authRepository.postSignIn(accessToken, RequestSignInModel(platform)).onSuccess {
tokenRepository.setTokens(it.accessToken, it.refreshToken)

_postChangeTokenState.value = SignInState.SUCCESS
Expand Down

0 comments on commit 837d0b2

Please sign in to comment.