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

🔀 :: (#30) - write the logic sign up #31

Merged
merged 19 commits into from
Jan 23, 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 @@ -2,6 +2,7 @@ package com.goms.goms_android_v2.navigation

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.lifecycle.viewmodel.compose.LocalViewModelStoreOwner
import androidx.navigation.compose.NavHost
import com.goms.goms_android_v2.ui.GomsAppState
import com.goms.login.navigation.inputLoginScreen
Expand All @@ -23,6 +24,7 @@ fun GomsNavHost(
startDestination: String = loginRoute
) {
val navController = appState.navController
val viewModelStoreOwner = checkNotNull(LocalViewModelStoreOwner.current)
NavHost(
navController = navController,
startDestination = startDestination,
Expand All @@ -36,16 +38,19 @@ fun GomsNavHost(
onBackClick = navController::popBackStack
)
signUpScreen(
viewModelStoreOwner = viewModelStoreOwner,
onBackClick = navController::popBackStack,
onNumberClick = navController::navigateToNumber
)
numberScreen(
viewModelStoreOwner = viewModelStoreOwner,
onBackClick = navController::popBackStack,
onPasswordClick = navController::navigateToPassword
)
passwordScreen(
viewModelStoreOwner = viewModelStoreOwner,
onBackClick = navController::popBackStack,
onLoginClick = navController::navigateToLogin
onLoginClick = { appState.navigateToTopLevelDestination(TopLevelDestination.LOGIN) }
)
}
}
18 changes: 18 additions & 0 deletions app/src/main/java/com/goms/goms_android_v2/ui/GomsAppState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.util.trace
import androidx.navigation.NavDestination
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navOptions
import com.goms.goms_android_v2.navigation.TopLevelDestination
import com.goms.login.navigation.loginRoute
import com.goms.login.navigation.navigateToLogin
import kotlinx.coroutines.CoroutineScope

@Composable
Expand Down Expand Up @@ -53,4 +57,18 @@ class GomsAppState(
get() = windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact

val topLevelDestinations: List<TopLevelDestination> = TopLevelDestination.values().asList()

fun navigateToTopLevelDestination(topLevelDestination: TopLevelDestination) {
trace("Navigation: ${topLevelDestination.name}") {
val topLevelNavOptions = navOptions {
popUpTo(navController.graph.findStartDestination().id) {
inclusive = true
}
}

when (topLevelDestination) {
TopLevelDestination.LOGIN -> navController.navigateToLogin(topLevelNavOptions)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package com.goms.data.repository.auth

import com.goms.model.request.auth.LoginRequest
import com.goms.model.request.auth.SendNumberRequest
import com.goms.model.request.auth.SignUpRequest
import com.goms.model.response.auth.LoginResponse
import kotlinx.coroutines.flow.Flow

interface AuthRepository {
suspend fun signUp(body: SignUpRequest): Flow<Unit>

suspend fun login(body: LoginRequest): Flow<LoginResponse>

suspend fun saveToken(token: LoginResponse)

suspend fun sendNumber(body: SendNumberRequest): Flow<Unit>

suspend fun verifyNumber(email: String, authCode: String): Flow<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.goms.data.repository.auth

import com.goms.datastore.AuthTokenDataSource
import com.goms.model.request.auth.LoginRequest
import com.goms.model.request.auth.SendNumberRequest
import com.goms.model.request.auth.SignUpRequest
import com.goms.model.response.auth.LoginResponse
import com.goms.network.datasource.auth.AuthDataSource
import kotlinx.coroutines.flow.Flow
Expand All @@ -11,6 +13,10 @@ class AuthRepositoryImpl @Inject constructor(
private val remoteAuthDataSource: AuthDataSource,
private val localAuthDataSource: AuthTokenDataSource
) : AuthRepository {
override suspend fun signUp(body: SignUpRequest): Flow<Unit> {
return remoteAuthDataSource.signUp(body = body)
}

override suspend fun login(body: LoginRequest): Flow<LoginResponse> {
return remoteAuthDataSource.login(body = body)
}
Expand All @@ -24,4 +30,12 @@ class AuthRepositoryImpl @Inject constructor(
localAuthDataSource.setAuthority(it.authority.name)
}
}

override suspend fun sendNumber(body: SendNumberRequest): Flow<Unit> {
return remoteAuthDataSource.sendNumber(body = body)
}

override suspend fun verifyNumber(email: String, authCode: String): Flow<Unit> {
return remoteAuthDataSource.verifyNumber(email = email, authCode = authCode)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -411,20 +411,21 @@ fun GomsPasswordTextField(
)
Column(
modifier = Modifier
.height(32.dp)
.height(50.dp)
.padding(start = 8.dp),
verticalArrangement = Arrangement.Center
) {
if (isError) {
if (!isFocused.value) {
Text(
text = errorText,
color = colors.N5,
text = "대/소문자, 특수문자 12자 이상",
color = colors.G4,
style = typography.buttonLarge
)
} else if (!isFocused.value) {
}
if (isError) {
Text(
text = "대/소문자, 특수문자 12자 이상",
color = colors.G4,
text = errorText,
color = colors.N5,
style = typography.buttonLarge
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.goms.design_system.util

fun isStrongPassword(password: String): Boolean {
val regex = Regex("^(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#\$%^&*(),.?\":{}|<>])(.{12,})\$")
return regex.matches(password)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.goms.domain.auth

import com.goms.data.repository.auth.AuthRepository
import com.goms.model.request.auth.SendNumberRequest
import javax.inject.Inject

class SendNumberUseCase @Inject constructor(
private val authRepository: AuthRepository
) {
suspend operator fun invoke(body: SendNumberRequest) = kotlin.runCatching {
authRepository.sendNumber(body = body)
}
}
13 changes: 13 additions & 0 deletions core/domain/src/main/java/com/goms/domain/auth/SighUpUseCase.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.goms.domain.auth

import com.goms.data.repository.auth.AuthRepository
import com.goms.model.request.auth.SignUpRequest
import javax.inject.Inject

class SighUpUseCase @Inject constructor(
private val authRepository: AuthRepository
) {
suspend operator fun invoke(body: SignUpRequest) = kotlin.runCatching {
authRepository.signUp(body = body)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.goms.domain.auth

import com.goms.data.repository.auth.AuthRepository
import javax.inject.Inject

class VerifyNumberUseCase @Inject constructor(
private val authRepository: AuthRepository
) {
suspend operator fun invoke(email: String, authCode: String) = kotlin.runCatching {
authRepository.verifyNumber(email = email, authCode = authCode)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.goms.model.request.auth

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class SendNumberRequest(
@Json(name = "email") val email: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.goms.model.request.auth

import com.goms.model.enum.Gender
import com.goms.model.enum.Major
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class SignUpRequest(
@Json(name = "email") val email: String,
@Json(name = "password") val password: String,
@Json(name = "name") val name: String,
@Json(name = "gender") val gender: String,
@Json(name = "major") val major: String
)
20 changes: 20 additions & 0 deletions core/network/src/main/java/com/goms/network/api/AuthAPI.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
package com.goms.network.api

import com.goms.model.request.auth.LoginRequest
import com.goms.model.request.auth.SendNumberRequest
import com.goms.model.request.auth.SignUpRequest
import com.goms.model.response.auth.LoginResponse
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Query

interface AuthAPI {
@POST("/api/v2/auth/signup")
suspend fun signUp(
@Body body: SignUpRequest
)

@POST("/api/v2/auth/signin")
suspend fun login(
@Body body: LoginRequest
): LoginResponse

@POST("/api/v2/auth/email/send")
suspend fun sendNumber(
@Body body: SendNumberRequest
)

@GET("/api/v2/auth/email/verify")
suspend fun verifyNumber(
@Query("email") email: String,
@Query("authCode") authCode: String
)
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package com.goms.network.datasource.auth

import com.goms.model.request.auth.LoginRequest
import com.goms.model.request.auth.SendNumberRequest
import com.goms.model.request.auth.SignUpRequest
import com.goms.model.response.auth.LoginResponse
import kotlinx.coroutines.flow.Flow

interface AuthDataSource {
suspend fun signUp(body: SignUpRequest): Flow<Unit>

suspend fun login(body: LoginRequest): Flow<LoginResponse>

suspend fun sendNumber(body: SendNumberRequest): Flow<Unit>

suspend fun verifyNumber(email: String, authCode: String): Flow<Unit>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.goms.network.datasource.auth

import com.goms.model.request.auth.LoginRequest
import com.goms.model.request.auth.SendNumberRequest
import com.goms.model.request.auth.SignUpRequest
import com.goms.model.response.auth.LoginResponse
import com.goms.network.api.AuthAPI
import com.goms.network.util.GomsApiHandler
Expand All @@ -13,11 +15,35 @@ import javax.inject.Inject
class AuthDataSourceImpl @Inject constructor(
private val authAPI: AuthAPI
) : AuthDataSource {
override suspend fun signUp(body: SignUpRequest): Flow<Unit> = flow {
emit(
GomsApiHandler<Unit>()
.httpRequest { authAPI.signUp(body = body) }
.sendRequest()
)
}.flowOn(Dispatchers.IO)

override suspend fun login(body: LoginRequest): Flow<LoginResponse> = flow {
emit(
GomsApiHandler<LoginResponse>()
.httpRequest { authAPI.login(body = body) }
.sendRequest()
)
}.flowOn(Dispatchers.IO)

override suspend fun sendNumber(body: SendNumberRequest): Flow<Unit> = flow {
emit(
GomsApiHandler<Unit>()
.httpRequest { authAPI.sendNumber(body = body) }
.sendRequest()
)
}.flowOn(Dispatchers.IO)

override suspend fun verifyNumber(email: String, authCode: String): Flow<Unit> = flow {
emit(
GomsApiHandler<Unit>()
.httpRequest { authAPI.verifyNumber(email = email, authCode = authCode) }
.sendRequest()
)
}.flowOn(Dispatchers.IO)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class AuthInterceptor @Inject constructor(
): Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
val response = chain.proceed(request)
val builder = request.newBuilder()
val currentTime = System.currentTimeMillis().toGomsTimeDate()
val ignorePath = listOf("/auth")
Expand All @@ -30,7 +31,7 @@ class AuthInterceptor @Inject constructor(

ignorePath.forEachIndexed { index, s ->
if (s == path && ignoreMethod[index] == method) {
return chain.proceed(request)
return response
}
}

Expand Down Expand Up @@ -77,6 +78,10 @@ class AuthInterceptor @Inject constructor(
val accessToken = dataSource.getAccessToken().first().replace("\"", "")
builder.addHeader("Authorization", "Bearer $accessToken")
}
return chain.proceed(builder.build())
return if (response.code == 204) {
response.newBuilder().code(200).build()
} else {
response
}
}
}
Loading
Loading