Skip to content

Commit

Permalink
Mod #38: 피드백 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
0se0 committed Jun 28, 2024
1 parent 73120a6 commit d9ef64f
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 31 deletions.
12 changes: 6 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Response<BaseResponseWithoutDataDto>> =
runCatching {
override suspend fun signup(user: RequestUserEntity): Result<Unit> {
return runCatching {
authDataSource.postSignUp(user)
}
}.fold(
onSuccess = { Result.Success(Unit) },
onFailure = { Result.Error(it) }
)
}

override suspend fun login(user: RequestSignInEntity): Result<Response<BaseResponseWithoutDataDto>> =
runCatching {
override suspend fun login(user: RequestSignInEntity): Result<Unit> {
return runCatching {
authDataSource.postSignIn(user)
}
}.fold(
onSuccess = { Result.Success(Unit) },
onFailure = { Result.Error(it) }
)
}

override suspend fun changePassword(user: RequestChangePasswordEntity): Result<Response<BaseResponseWithoutDataDto>> =
runCatching {

override suspend fun changePassword(user: RequestChangePasswordEntity): Result<Unit> {
return runCatching {
authDataSource.postChangePassword(user)
}
}.fold(
onSuccess = { Result.Success(Unit) },
onFailure = { Result.Error(it) }
)
}

override fun getId() = userDataStore.id
override fun getPassword() = userDataStore.password
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.sopt.now.compose.domain.entity

sealed class Result<out T> {
data class Success<out T>(val data: T) : Result<T>()
data class Error(val exception: Throwable) : Result<Nothing>()
}
Original file line number Diff line number Diff line change
@@ -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<Response<BaseResponseWithoutDataDto>>
suspend fun login(user: RequestSignInEntity): Result<Response<BaseResponseWithoutDataDto>>
suspend fun changePassword(user: RequestChangePasswordEntity): Result<Response<BaseResponseWithoutDataDto>>
suspend fun signup(user: RequestUserEntity): Result<Unit>
suspend fun login(user: RequestSignInEntity): Result<Unit>
suspend fun changePassword(user: RequestChangePasswordEntity): Result<Unit>
fun getId(): String
fun getPassword(): String
fun getNickname(): String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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 }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,4 @@ class SignupViewModel @Inject constructor(
message = "회원가입 실패 $error"
)
}

sealed class SignupSideEffect {
data class ShowError(val message: String) : SignupSideEffect()
data object NavigateToMain : SignupSideEffect()
}
}

0 comments on commit d9ef64f

Please sign in to comment.