-
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?
Conversation
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.
composeκΉμ§ μλ²½νκ²!! xmlμμ μ΄λ―Έ λ무 λ§μ κ°νμ ν΄λ²λ Έλ€μ..
κ³ μ λ§μΌμ
¨μ΅λλ€!! μ
€ ν§ν
><
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.
ν νκΈ°λμ λ무 κ³ μλ§μμ΄!!
κ³ λ§μγ
γ
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}") | ||
} | ||
} | ||
} |
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.
κ° viewdmodel λ³λ‘ factoryλ₯Ό λ°λ‘ λ§λ€ νμλ μμ΄ λ³΄μ
λλ€! λΆνμν μ½λκ° μ¦κ°νλ κ² κ°μμ
λ νλμ μΌλ°μ μΈ factoryν΄λμ€λ₯Ό ν΅ν΄ ν©ν 리 λ‘μ§μ μ€μμ§μ€ν ν μ μμ΅λλ€. νμ₯μ±λ λ μ’ꡬμ
μ μ»΄ν¬μ¦ prμμ viewmodel factoryλ₯Ό νλλ‘ μ¬μ©νλ μ½λ μ°Έκ³ ν΄λ³΄μλ©΄ μ’μκ² κ°μμ~!!
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.
else ifλ whenμ λ‘ λΆκΈ°μ²λ¦¬λ§ νλ©΄ λ©λλ€
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 comment
The reason will be displayed to describe this comment to others. Learn more.
ν΄λΉ repsitoryλ dataλ μ΄μ΄λ‘ κ°λ κ²μ΄ μ’μ΅λλ€!
λν returnνμ
μΌλ‘ Responseνμ
μ΄ μλ Resultνμ
μ μ¬μ©ν΄μ£ΌμΈμ!
Response νμ μ μ¬μ©νλ©΄ λ€νΈμν¬ μλ΅μ μ§μ μ²λ¦¬ν΄μΌ νλ©°, μ±κ³΅κ³Ό μ€ν¨μ λν λ‘μ§μ λͺ μμ μΌλ‘ μμ±ν΄μΌ ν©λλ€. λ retroiftμ΄λΌλ λΌμ΄λΈλ¬λ¦¬μ μμ‘΄μ μ΄ λ¨μ μ΄ μμ΄μ©
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.
κΈ°νκ²½μ λ μλ €μ£Όμ ¨λ λΆλΆμ΄λ€μ λ€μνλ² λ¦¬λ§μΈλλ λκ³ λ§μ΄ λ°°μκ°μ
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>() | ||
} |
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.
goood!!
seale interfaceλ νλ² μ¬μ©ν΄λ³΄μΈμγ
γ
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.
μνκΈ°κ°μ΄λΌ λ°μ ν
λ°λ κ³Όμ λ€νλλΌ κ³ μνμ
¨μ΄μ!
λ§μ΄ λ°°μ°κΈ°λ§ νκ³ λμμ λ§μ΄ λͺ»μ€¬λκ² κ°μμ μμ½λ€μ
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 comment
The reason will be displayed to describe this comment to others. Learn more.
runCatch ꡬ문μ Repositoryimpl λ΄μμ μ²λ¦¬ν μ μμ΄μ!
κ·Όλ° μ¬κΈ°μ μ²λ¦¬νλκ² λ μ³μ κΈΈμΈμ§ λͺ°λΌμ
rucCatchλ₯Ό Repositoryimplμμ μ¬μ©ν μ μλ€ μ λλ§ λ¨κ²¨λκ²μ
class AuthRepositoryImpl( | ||
private val authService: AuthService | ||
) : AuthRepository { | ||
override suspend fun loginUser(data: RequestLoginDto): Response<BaseResponse<Unit>> { |
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.
override suspend fun loginUser(data: RequestLoginDto): Response<BaseResponse<Unit>> { | |
override suspend fun loginUser(data: RequestLoginDto): Response<BaseResponse<Unit>> =runCatching { | |
authService.login(data) | |
} |
μ΄μ²λΌ νλ©΄ runCatchμ ν΄λΉνλ λ‘μ§μ μ¬κΈ°μ λ£μ μ λ μμ΄μ!
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 comment
The reason will be displayed to describe this comment to others. Learn more.
κΈ°νκ²½μ λ μλ €μ£Όμ ¨λ λΆλΆμ΄λ€μ λ€μνλ² λ¦¬λ§μΈλλ λκ³ λ§μ΄ λ°°μκ°μ
πππ΄π΄πΆπ¦π΄
πππ°π³π¬ ππ¦π΄π€π³πͺπ±π΅πͺπ°π―
π·ππ€π³π¦π¦π―π΄π©π°π΅
compose07.mp4