Skip to content

Commit

Permalink
[feature/#1011] 로그인 서버통신 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
leeeyubin committed Jan 2, 2025
1 parent 070e12a commit 8aeaa09
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.sopt.official.feature.auth.feature.authmain

sealed class AuthMainSideEffect {
data class ShowToast(val message: String) : AuthMainSideEffect()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.sopt.official.feature.auth.feature.authmain

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.launch
import org.sopt.official.domain.auth.model.SignInCode
import org.sopt.official.domain.auth.repository.AuthRepository
import javax.inject.Inject

@HiltViewModel
class AuthMainViewModel @Inject constructor(
private val authRepository: AuthRepository,
// private val oAuthInteractor: OAuthInteractor
) : ViewModel() {

private val _sideEffect = MutableSharedFlow<AuthMainSideEffect>()
val sideEffect: SharedFlow<AuthMainSideEffect> = _sideEffect.asSharedFlow()

fun signIn(code: String) {
// TODO: 실제 code 넣기 by leeeyubin
viewModelScope.launch {
authRepository.signIn(
SignInCode(
code = "codecodecodecodecode",
authPlatform = GOOGLE
)
).onSuccess {
_sideEffect.emit(AuthMainSideEffect.ShowToast("성공!!"))
}.onFailure {
_sideEffect.emit(AuthMainSideEffect.ShowToast("실패ㅠㅠ!!"))
}
}
}

companion object {
private const val GOOGLE = "GOOGLE"
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.sopt.official.data.auth.mapper

import org.sopt.official.data.auth.remote.request.SignInRequest
import org.sopt.official.data.auth.remote.response.SignInResponse
import org.sopt.official.domain.auth.model.SignInCode
import org.sopt.official.domain.auth.model.SignInResult

fun SignInCode.toRequest(): SignInRequest =
SignInRequest(
code = code,
authPlatform = authPlatform
)

fun SignInResponse.toDomain(): SignInResult =
SignInResult(
accessToken = accessToken,
refreshToken = refreshToken
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import org.sopt.official.data.auth.model.BaseAuthResponse
import org.sopt.official.data.auth.model.NonDataBaseAuthResponse
import org.sopt.official.data.auth.remote.request.CertificateCodeRequest
import org.sopt.official.data.auth.remote.request.CreateCodeRequest
import org.sopt.official.data.auth.remote.request.SignInRequest
import org.sopt.official.data.auth.remote.response.CertificateCodeResponse
import org.sopt.official.data.auth.remote.response.SignInResponse
import retrofit2.http.Body
import retrofit2.http.POST

Expand All @@ -18,4 +20,9 @@ internal interface AuthApi {
suspend fun certificateCode(
@Body request: CertificateCodeRequest,
): BaseAuthResponse<CertificateCodeResponse>

@POST("/api/v1/auth/login/app")
suspend fun signIn(
@Body request: SignInRequest,
): BaseAuthResponse<SignInResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.sopt.official.data.auth.remote.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class SignInRequest (
@SerialName("code")
val code: String,
@SerialName("authPlatform")
val authPlatform: String
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.sopt.official.data.auth.remote.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class SignInResponse(
@SerialName("accessToken")
val accessToken: String,
@SerialName("refreshToken")
val refreshToken: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.sopt.official.domain.auth.model

data class SignInCode(
val code: String,
val authPlatform: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.sopt.official.domain.auth.model

data class SignInResult(
val accessToken: String,
val refreshToken: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ package org.sopt.official.domain.auth.repository

import org.sopt.official.domain.auth.model.InformationWithCode
import org.sopt.official.domain.auth.model.InitialInformation
import org.sopt.official.domain.auth.model.SignInCode
import org.sopt.official.domain.auth.model.SignInResult
import org.sopt.official.domain.auth.model.VerificationResult

interface AuthRepository {
suspend fun createCode(request: InitialInformation): Result<Unit>

suspend fun certificateCode(request: InformationWithCode): Result<VerificationResult>

suspend fun signIn(request: SignInCode): Result<SignInResult>
}

0 comments on commit 8aeaa09

Please sign in to comment.