Skip to content

Commit

Permalink
[FEAT]#30: 회원가입을 진행해요
Browse files Browse the repository at this point in the history
  • Loading branch information
flash159483 committed Jul 17, 2024
1 parent 4374fa7 commit 37bcf3d
Show file tree
Hide file tree
Showing 23 changed files with 147 additions and 17 deletions.
3 changes: 2 additions & 1 deletion app/src/main/kotlin/com/bff/wespot/NavigatorImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import android.content.Context
import android.content.Intent
import com.danggeun.navigation.Navigator
import com.danggeun.navigation.util.buildIntent
import javax.inject.Inject

class NavigatorImpl : Navigator {
class NavigatorImpl @Inject constructor() : Navigator {
override fun navigateToMain(
context: Context,
): Intent {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/com/bff/wespot/di/NavigationModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ import javax.inject.Singleton
interface NavigationModule {
@Binds
@Singleton
fun provideNavigator(navigator: NavigatorImpl): Navigator
fun bindsNavigator(navigator: NavigatorImpl): Navigator
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package com.bff.wespot.model.auth.request
data class KakaoAuthToken(
val accessToken: String,
val idToken: String?,
val socialType: String = "KAKAO"
val socialType: String = "KAKAO",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.bff.wespot.model.auth.request

data class SignUp(
val schoolId: Int,
val grade: Int,
val group: Int,
val gender: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package com.bff.wespot.model.auth.response
data class AuthToken(
val accessToken: String,
val refreshToken: String,
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ inline fun <reified T : Activity> Context.buildIntent(
vararg argument: Pair<String, Any?>,
) = Intent(this, T::class.java).apply {
putExtras(bundleOf(*argument))
}

inline fun <reified T : Activity> Context.navigateActivity(
vararg argument: Pair<String, Any?>,
) {
startActivity(buildIntent<T>(*argument))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.bff.wespot.network.model.auth.request

import kotlinx.serialization.Serializable

@Serializable
data class SignUpDto(
val schoolId: Int,
val grade: Int,
val group: Int,
val gender: String,
val userToken: String,
)
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.bff.wespot.network.source.auth

import com.bff.wespot.network.model.auth.request.KakaoAuthTokenDto
import com.bff.wespot.network.model.auth.request.SignUpDto
import com.bff.wespot.network.model.auth.response.AuthTokenDto
import com.bff.wespot.network.model.auth.response.SchoolListDto

interface AuthDataSource {
suspend fun getSchoolList(search: String): Result<SchoolListDto>
suspend fun sendKakaoToken(token: KakaoAuthTokenDto): Result<AuthTokenDto>
suspend fun signUp(signUp: SignUpDto): Result<AuthTokenDto>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.bff.wespot.network.source.auth

import com.bff.wespot.network.extensions.safeRequest
import com.bff.wespot.network.model.auth.request.KakaoAuthTokenDto
import com.bff.wespot.network.model.auth.request.SignUpDto
import com.bff.wespot.network.model.auth.response.AuthTokenDto
import com.bff.wespot.network.model.auth.response.SchoolListDto
import io.ktor.client.HttpClient
Expand Down Expand Up @@ -31,4 +32,13 @@ class AuthDataSourceImpl @Inject constructor(
}
setBody(token)
}

override suspend fun signUp(signUp: SignUpDto): Result<AuthTokenDto> =
httpClient.safeRequest {
url {
method = HttpMethod.Post
path("api/v1/auth/signup")
}
setBody(signUp)
}
}
11 changes: 11 additions & 0 deletions data/src/main/kotlin/com/bff/wespot/data/mapper/auth/AuthMapper.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
package com.bff.wespot.data.mapper.auth

import com.bff.wespot.model.auth.request.KakaoAuthToken
import com.bff.wespot.model.auth.request.SignUp
import com.bff.wespot.network.model.auth.request.KakaoAuthTokenDto
import com.bff.wespot.network.model.auth.request.SignUpDto

internal fun KakaoAuthToken.toDto() =
KakaoAuthTokenDto(
socialType = socialType,
identityToken = idToken ?: "",
)

internal fun SignUp.toDto(token: String) =
SignUpDto(
schoolId = schoolId,
grade = grade,
group = group,
gender = gender,
userToken = token,
)
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package com.bff.wespot.data.repository.auth

import com.bff.wespot.data.local.WeSpotDataStore
import com.bff.wespot.data.mapper.auth.toDto
import com.bff.wespot.domain.repository.auth.AuthRepository
import com.bff.wespot.domain.util.DataStoreKey
import com.bff.wespot.model.auth.request.KakaoAuthToken
import com.bff.wespot.model.auth.request.SignUp
import com.bff.wespot.model.auth.response.AuthToken
import com.bff.wespot.model.auth.response.School
import com.bff.wespot.network.model.auth.response.SchoolDto
import com.bff.wespot.network.source.auth.AuthDataSource
import kotlinx.coroutines.flow.first
import javax.inject.Inject

class AuthRepositoryImpl @Inject constructor(
private val authDataSource: AuthDataSource
private val authDataSource: AuthDataSource,
private val dataStore: WeSpotDataStore
) : AuthRepository {
override suspend fun getSchoolList(search: String): Result<List<School>> =
authDataSource
Expand All @@ -21,4 +26,14 @@ class AuthRepositoryImpl @Inject constructor(
authDataSource
.sendKakaoToken(token.toDto())
.map { it.toAuthToken() }

override suspend fun signUp(signUp: SignUp): Boolean {
return authDataSource
.signUp(
signUp.toDto(
dataStore.getString(DataStoreKey.ACCESS_TOKEN).first()
)
).isSuccess
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ interface DataStoreRepository {
fun getString(key: String): Flow<String>
suspend fun saveBoolean(key: String, value: Boolean)
fun getBoolean(key: String): Flow<Boolean>
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.bff.wespot.domain.repository.auth

import com.bff.wespot.model.auth.request.KakaoAuthToken
import com.bff.wespot.model.auth.request.SignUp
import com.bff.wespot.model.auth.response.AuthToken
import com.bff.wespot.model.auth.response.School

interface AuthRepository {
suspend fun getSchoolList(search: String): Result<List<School>>
suspend fun sendKakaoToken(token: KakaoAuthToken): Result<AuthToken>
suspend fun signUp(signUp: SignUp): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import com.bff.wespot.domain.repository.auth.AuthRepository
import com.bff.wespot.domain.repository.auth.KakaoLoginManager
import com.bff.wespot.domain.util.DataStoreKey
import javax.inject.Inject
import javax.xml.crypto.Data

class KakaoLoginUseCase @Inject constructor(
val kakaoLoginManager: KakaoLoginManager,
val authRepository: AuthRepository,
val dataStoreRepository: DataStoreRepository
val dataStoreRepository: DataStoreRepository,
) {
suspend inline fun invoke() {
val result = kakaoLoginManager.loginWithKakao()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package com.bff.wespot.domain.util
object DataStoreKey {
const val ACCESS_TOKEN = "access_token"
const val REFRESH_TOKEN = "refresh_token"
}
}
1 change: 1 addition & 0 deletions feature/auth/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies {
implementation(project(":core:model"))
implementation(project(":core:ui"))
implementation(project(":designsystem"))
implementation(project(":core:navigation"))

implementation(libs.bundles.androidx.compose)
implementation(libs.bundles.orbit)
Expand Down
25 changes: 24 additions & 1 deletion feature/auth/src/main/kotlin/com/bff/wespot/auth/AuthActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ package com.bff.wespot.auth
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Surface
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.compose.rememberNavController
import com.bff.wespot.auth.screen.NavGraphs
Expand All @@ -19,21 +24,29 @@ import com.bff.wespot.auth.screen.destinations.SchoolScreenDestination
import com.bff.wespot.auth.state.AuthSideEffect
import com.bff.wespot.auth.viewmodel.AuthViewModel
import com.bff.wespot.designsystem.theme.WeSpotTheme
import com.danggeun.navigation.Navigator
import com.ramcosta.composedestinations.DestinationsNavHost
import com.ramcosta.composedestinations.navigation.dependency
import com.ramcosta.composedestinations.navigation.navigate
import com.ramcosta.composedestinations.rememberNavHostEngine
import dagger.hilt.android.AndroidEntryPoint
import org.orbitmvi.orbit.compose.collectAsState
import org.orbitmvi.orbit.compose.collectSideEffect
import javax.inject.Inject

@AndroidEntryPoint
class AuthActivity : ComponentActivity() {
@Inject
lateinit var navigator: Navigator

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val navController = rememberNavController()
val engine = rememberNavHostEngine()
val viewModel: AuthViewModel = viewModel()
val viewModel: AuthViewModel = hiltViewModel()

val state by viewModel.collectAsState()

viewModel.collectSideEffect {
when (it) {
Expand Down Expand Up @@ -67,6 +80,10 @@ class AuthActivity : ComponentActivity() {
popUpTo(SchoolScreenDestination.route) { inclusive = true }
})
}

AuthSideEffect.NavigateToMainActivity -> {
navigator.navigateToMain(this)
}
}
}

Expand All @@ -84,6 +101,12 @@ class AuthActivity : ComponentActivity() {
)
}
}

if (state.loading) {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
CircularProgressIndicator()
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,23 @@ fun AuthScreen(
.clip(RoundedCornerShape(6.dp))
.background(Color(0xFFFEE500)),
colors = ButtonDefaults.buttonColors(
containerColor = Color(0xFFFEE500)
containerColor = Color(0xFFFEE500),
),
) {
Icon(
painter = painterResource(id = R.drawable.kakao),
contentDescription = stringResource(
id = R.string.kakao_icon
id = R.string.kakao_icon,
),
tint = Color.Black
tint = Color.Black,
)

Spacer(modifier = Modifier.width(8.dp))

Text(
text = stringResource(id = R.string.continue_with_kakao),
style = StaticTypeScale.Default.body4.copy(fontWeight = FontWeight.Bold),
color = Color.Black
color = Color.Black,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import com.bff.wespot.auth.R
import com.bff.wespot.auth.state.AuthAction
import com.bff.wespot.auth.viewmodel.AuthViewModel
import com.bff.wespot.designsystem.component.button.WSButton
import com.bff.wespot.designsystem.component.button.WSOutlineButton
import com.bff.wespot.designsystem.component.modal.WSDialog
import com.ramcosta.composedestinations.annotation.Destination

@Composable
@Destination
fun CompleteScreen() {
fun CompleteScreen(
viewModel: AuthViewModel,
) {
var dialog by remember {
mutableStateOf(false)
}
Expand All @@ -35,7 +39,9 @@ fun CompleteScreen() {
it.invoke()
}

WSOutlineButton(onClick = { }, text = stringResource(id = R.string.start)) {
WSOutlineButton(onClick = {
viewModel.onAction(AuthAction.signUp)
}, text = stringResource(id = R.string.start)) {
it.invoke()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ sealed class AuthAction {

data object LoginWithKakao : AuthAction()

data object signUp : AuthAction()

data class Navigation(val navigate: NavigationAction) : AuthAction()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ sealed class AuthSideEffect {
data class NavigateToClassScreen(val edit: Boolean) : AuthSideEffect()
data class NavigateToGenderScreen(val edit: Boolean) : AuthSideEffect()
data class NavigateToNameScreen(val edit: Boolean) : AuthSideEffect()
data object NavigateToMainActivity : AuthSideEffect()
data object NavigateToEditScreen : AuthSideEffect()
data object NavigateToCompleteScreen : AuthSideEffect()
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ data class AuthUiState(
val classNumber: Int = -1,
val gender: String = "",
val name: String = "",
val loading: Boolean = false,
)
Loading

0 comments on commit 37bcf3d

Please sign in to comment.