-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feat/week compose07 #20
base: develop-compose
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.sopt.now.compose.data | ||
|
||
import com.sopt.now.compose.datasource.AuthService | ||
import com.sopt.now.compose.model.login.RequestLoginDto | ||
import com.sopt.now.compose.model.signup.RequestSignUpDto | ||
import com.sopt.now.compose.repository.AuthRepository | ||
import com.sopt.now.compose.utils.BaseResponse | ||
import retrofit2.Response | ||
|
||
class AuthRepositoryImpl( | ||
private val authService: AuthService | ||
) : AuthRepository { | ||
override suspend fun loginUser(data: RequestLoginDto): Response<BaseResponse<Unit>> { | ||
return authService.login(data) | ||
} | ||
|
||
override suspend fun signUp(data: RequestSignUpDto): Response<BaseResponse<Unit>> { | ||
return authService.signUp(data) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.sopt.now.compose.data | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
import com.sopt.now.compose.presentation.auth.login.LoginViewModel | ||
import com.sopt.now.compose.utils.ServicePool | ||
|
||
class LoginViewModelFactory: ViewModelProvider.Factory { | ||
override fun <T : ViewModel> create(modelClass: Class<T>): T { | ||
if (modelClass.isAssignableFrom(LoginViewModel::class.java)) { | ||
val repository = AuthRepositoryImpl(ServicePool.loginService) | ||
return LoginViewModel(repository) as T | ||
} else { | ||
throw IllegalArgumentException("fail ${modelClass.name}") | ||
} | ||
} | ||
} | ||
Comment on lines
+8
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. κ° viewdmodel λ³λ‘ factoryλ₯Ό λ°λ‘ λ§λ€ νμλ μμ΄ λ³΄μ
λλ€! λΆνμν μ½λκ° μ¦κ°νλ κ² κ°μμ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. else ifλ whenμ λ‘ λΆκΈ°μ²λ¦¬λ§ νλ©΄ λ©λλ€ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.sopt.now.compose.data | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
import com.sopt.now.compose.presentation.auth.signup.SignUpViewModel | ||
import com.sopt.now.compose.utils.ServicePool | ||
|
||
class SignUpViewModelFactory : ViewModelProvider.Factory { | ||
override fun <T : ViewModel> create(modelClass: Class<T>): T { | ||
if (modelClass.isAssignableFrom(SignUpViewModel::class.java)) { | ||
val repository = AuthRepositoryImpl(ServicePool.authService) | ||
return SignUpViewModel(repository) as T | ||
} else { | ||
throw IllegalArgumentException("fail ${modelClass.name}") | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package com.sopt.now.compose.presentation.auth.signup | |
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.sopt.now.compose.model.signup.RequestSignUpDto | ||
import com.sopt.now.compose.repository.AuthRepository | ||
import com.sopt.now.compose.utils.NetworkUtil | ||
import com.sopt.now.compose.utils.ServicePool.authService | ||
import com.sopt.now.compose.utils.UiState | ||
|
@@ -11,15 +12,17 @@ import kotlinx.coroutines.flow.MutableStateFlow | |
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.launch | ||
|
||
class SignUpViewModel : ViewModel() { | ||
private val _state = MutableStateFlow<UiState>(UiState.LOADING) | ||
class SignUpViewModel( | ||
private val authRepository: AuthRepository | ||
) : ViewModel() { | ||
private val _state = MutableStateFlow<UiState<Unit>>(UiState.LOADING) | ||
val state = _state.asStateFlow() | ||
|
||
fun signUp(data: RequestSignUpDto) { | ||
viewModelScope.launch(Dispatchers.IO) { | ||
_state.value = UiState.LOADING | ||
runCatching { | ||
authService.signUp(data) | ||
authRepository.signUp(data) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. runCatch ꡬ문μ Repositoryimpl λ΄μμ μ²λ¦¬ν μ μμ΄μ! |
||
}.onSuccess { | ||
if (it.isSuccessful) _state.value = UiState.SUCCESS<Unit>() | ||
else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.sopt.now.compose.repository | ||
|
||
import com.sopt.now.compose.model.login.RequestLoginDto | ||
import com.sopt.now.compose.model.signup.RequestSignUpDto | ||
import com.sopt.now.compose.utils.BaseResponse | ||
import retrofit2.Response | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ν΄λΉ repsitoryλ dataλ μ΄μ΄λ‘ κ°λ κ²μ΄ μ’μ΅λλ€! Response νμ μ μ¬μ©νλ©΄ λ€νΈμν¬ μλ΅μ μ§μ μ²λ¦¬ν΄μΌ νλ©°, μ±κ³΅κ³Ό μ€ν¨μ λν λ‘μ§μ λͺ μμ μΌλ‘ μμ±ν΄μΌ ν©λλ€. λ retroiftμ΄λΌλ λΌμ΄λΈλ¬λ¦¬μ μμ‘΄μ μ΄ λ¨μ μ΄ μμ΄μ© There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. κΈ°νκ²½μ λ μλ €μ£Όμ ¨λ λΆλΆμ΄λ€μ λ€μνλ² λ¦¬λ§μΈλλ λκ³ λ§μ΄ λ°°μκ°μ |
||
|
||
interface AuthRepository { | ||
suspend fun loginUser(data: RequestLoginDto): Response<BaseResponse<Unit>> | ||
|
||
suspend fun signUp(data: RequestSignUpDto): Response<BaseResponse<Unit>> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
package com.sopt.now.compose.utils | ||
|
||
sealed class UiState { | ||
data object LOADING : UiState() | ||
sealed class UiState<out T> { | ||
data object LOADING : UiState<Nothing>() | ||
data class SUCCESS<T>( | ||
val data: T? = null | ||
) : UiState() | ||
) : UiState<T>() | ||
|
||
data class FAILURE( | ||
val errorMessage: String | ||
) : UiState() | ||
) : UiState<Nothing>() | ||
} | ||
Comment on lines
+3
to
12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. goood!! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ΄μ²λΌ νλ©΄ runCatchμ ν΄λΉνλ λ‘μ§μ μ¬κΈ°μ λ£μ μ λ μμ΄μ!