diff --git a/app/build.gradle b/app/build.gradle index c33f6c9..d4e24b0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -65,24 +65,24 @@ dependencies { implementation 'androidx.compose.ui:ui-tooling-preview' implementation 'androidx.compose.material3:material3' testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.5' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' - androidTestImplementation platform('androidx.compose:compose-bom:2024.05.00') + androidTestImplementation 'androidx.test.ext:junit:1.2.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' + androidTestImplementation platform('androidx.compose:compose-bom:2024.06.00') androidTestImplementation 'androidx.compose.ui:ui-test-junit4' debugImplementation 'androidx.compose.ui:ui-tooling' debugImplementation 'androidx.compose.ui:ui-test-manifest' - implementation 'androidx.compose.runtime:runtime-livedata:1.6.7' + implementation 'androidx.compose.runtime:runtime-livedata:1.6.8' implementation 'androidx.navigation:navigation-compose:2.7.7' implementation 'androidx.constraintlayout:constraintlayout-compose:1.0.1' implementation 'com.brandongogetap:stickyheaders:0.6.2' implementation 'com.squareup.retrofit2:retrofit:2.11.0' - implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3' + implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.0' implementation 'com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:1.0.0' implementation(platform 'com.squareup.okhttp3:okhttp-bom:4.10.0') implementation 'com.squareup.okhttp3:okhttp' implementation 'com.squareup.okhttp3:logging-interceptor' implementation "io.coil-kt:coil-compose:2.6.0" - implementation 'androidx.lifecycle:lifecycle-runtime-compose:2.8.1' + implementation 'androidx.lifecycle:lifecycle-runtime-compose:2.8.2' implementation "com.google.dagger:hilt-android:$hilt_version" kapt "com.google.dagger:hilt-compiler:$hilt_version" diff --git a/app/src/main/java/com/sopt/now/compose/data/remote/repositoryImpl/AuthRepositoryImpl.kt b/app/src/main/java/com/sopt/now/compose/data/remote/repositoryImpl/AuthRepositoryImpl.kt index 0f31997..3bad9a6 100644 --- a/app/src/main/java/com/sopt/now/compose/data/remote/repositoryImpl/AuthRepositoryImpl.kt +++ b/app/src/main/java/com/sopt/now/compose/data/remote/repositoryImpl/AuthRepositoryImpl.kt @@ -2,32 +2,44 @@ package com.sopt.now.compose.data.remote.repositoryImpl import com.sopt.now.compose.data.local.UserDataStore import com.sopt.now.compose.data.remote.datasource.AuthDataSource -import com.sopt.now.compose.data.remote.response.BaseResponseWithoutDataDto import com.sopt.now.compose.domain.entity.request.RequestChangePasswordEntity import com.sopt.now.compose.domain.entity.request.RequestSignInEntity import com.sopt.now.compose.domain.entity.request.RequestUserEntity import com.sopt.now.compose.domain.repository.AuthRepository -import retrofit2.Response +import com.sopt.now.compose.domain.entity.Result import javax.inject.Inject class AuthRepositoryImpl @Inject constructor( private val authDataSource: AuthDataSource, private val userDataStore: UserDataStore ) : AuthRepository { - override suspend fun signup(user: RequestUserEntity): Result> = - runCatching { + override suspend fun signup(user: RequestUserEntity): Result { + return runCatching { authDataSource.postSignUp(user) - } + }.fold( + onSuccess = { Result.Success(Unit) }, + onFailure = { Result.Error(it) } + ) + } - override suspend fun login(user: RequestSignInEntity): Result> = - runCatching { + override suspend fun login(user: RequestSignInEntity): Result { + return runCatching { authDataSource.postSignIn(user) - } + }.fold( + onSuccess = { Result.Success(Unit) }, + onFailure = { Result.Error(it) } + ) + } - override suspend fun changePassword(user: RequestChangePasswordEntity): Result> = - runCatching { + + override suspend fun changePassword(user: RequestChangePasswordEntity): Result { + return runCatching { authDataSource.postChangePassword(user) - } + }.fold( + onSuccess = { Result.Success(Unit) }, + onFailure = { Result.Error(it) } + ) + } override fun getId() = userDataStore.id override fun getPassword() = userDataStore.password diff --git a/app/src/main/java/com/sopt/now/compose/domain/entity/Result.kt b/app/src/main/java/com/sopt/now/compose/domain/entity/Result.kt new file mode 100644 index 0000000..625bb1b --- /dev/null +++ b/app/src/main/java/com/sopt/now/compose/domain/entity/Result.kt @@ -0,0 +1,6 @@ +package com.sopt.now.compose.domain.entity + +sealed class Result { + data class Success(val data: T) : Result() + data class Error(val exception: Throwable) : Result() +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/domain/repository/AuthRepository.kt b/app/src/main/java/com/sopt/now/compose/domain/repository/AuthRepository.kt index a8260e5..01f9e9a 100644 --- a/app/src/main/java/com/sopt/now/compose/domain/repository/AuthRepository.kt +++ b/app/src/main/java/com/sopt/now/compose/domain/repository/AuthRepository.kt @@ -1,15 +1,14 @@ package com.sopt.now.compose.domain.repository -import com.sopt.now.compose.data.remote.response.BaseResponseWithoutDataDto import com.sopt.now.compose.domain.entity.request.RequestChangePasswordEntity import com.sopt.now.compose.domain.entity.request.RequestSignInEntity import com.sopt.now.compose.domain.entity.request.RequestUserEntity -import retrofit2.Response +import com.sopt.now.compose.domain.entity.Result interface AuthRepository { - suspend fun signup(user: RequestUserEntity): Result> - suspend fun login(user: RequestSignInEntity): Result> - suspend fun changePassword(user: RequestChangePasswordEntity): Result> + suspend fun signup(user: RequestUserEntity): Result + suspend fun login(user: RequestSignInEntity): Result + suspend fun changePassword(user: RequestChangePasswordEntity): Result fun getId(): String fun getPassword(): String fun getNickname(): String diff --git a/app/src/main/java/com/sopt/now/compose/ui/signup/SignupScreen.kt b/app/src/main/java/com/sopt/now/compose/ui/signup/SignupScreen.kt index 9c1aefa..2ef3962 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/signup/SignupScreen.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/signup/SignupScreen.kt @@ -19,7 +19,6 @@ import androidx.compose.material3.SnackbarHostState import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.livedata.observeAsState import androidx.compose.runtime.remember @@ -32,6 +31,7 @@ import androidx.compose.ui.text.input.PasswordVisualTransformation import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.hilt.navigation.compose.hiltViewModel +import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.navigation.NavController import com.sopt.now.compose.R import com.sopt.now.compose.util.noRippleClickable @@ -40,7 +40,7 @@ import kotlinx.coroutines.flow.collectLatest @Composable fun SignupRoute(navController: NavController, viewModel: SignupViewModel = hiltViewModel()) { val snackbarHostState = remember { SnackbarHostState() } - val signUpState by viewModel.signUpState.collectAsState() + val signUpState by viewModel.signUpState.collectAsStateWithLifecycle() val authState by viewModel.signupStatus.observeAsState(null) LaunchedEffect(authState) { @@ -57,14 +57,14 @@ fun SignupRoute(navController: NavController, viewModel: SignupViewModel = hiltV LaunchedEffect(viewModel.sideEffect) { viewModel.sideEffect.collectLatest { sideEffect -> when (sideEffect) { - is SignupViewModel.SignupSideEffect.ShowError -> { + is SignupSideEffect.ShowError -> { snackbarHostState.showSnackbar( message = sideEffect.message, duration = SnackbarDuration.Short ) } - SignupViewModel.SignupSideEffect.NavigateToMain -> { + SignupSideEffect.NavigateToMain -> { navController.navigate("login") { popUpTo("signup") { inclusive = true } } diff --git a/app/src/main/java/com/sopt/now/compose/ui/signup/SignupSideEffect.kt b/app/src/main/java/com/sopt/now/compose/ui/signup/SignupSideEffect.kt new file mode 100644 index 0000000..4ee7a25 --- /dev/null +++ b/app/src/main/java/com/sopt/now/compose/ui/signup/SignupSideEffect.kt @@ -0,0 +1,6 @@ +package com.sopt.now.compose.ui.signup + +sealed class SignupSideEffect { + data class ShowError(val message: String) : SignupSideEffect() + data object NavigateToMain : SignupSideEffect() + } \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/compose/ui/signup/SignupViewModel.kt b/app/src/main/java/com/sopt/now/compose/ui/signup/SignupViewModel.kt index ef39322..f8d5c4c 100644 --- a/app/src/main/java/com/sopt/now/compose/ui/signup/SignupViewModel.kt +++ b/app/src/main/java/com/sopt/now/compose/ui/signup/SignupViewModel.kt @@ -98,9 +98,4 @@ class SignupViewModel @Inject constructor( message = "회원가입 실패 $error" ) } - - sealed class SignupSideEffect { - data class ShowError(val message: String) : SignupSideEffect() - data object NavigateToMain : SignupSideEffect() - } } \ No newline at end of file