-
Notifications
You must be signed in to change notification settings - Fork 0
7주차 필수과제 #22
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
base: 6주차-필수,심화
Are you sure you want to change the base?
The head ref may contain hidden characters: "7\uC8FC\uCC28-\uD544\uC218\uACFC\uC81C"
7주차 필수과제 #22
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 |
|---|---|---|
| @@ -1,33 +1,34 @@ | ||
| package org.sopt.dosopttemplate.presentation.auth | ||
|
|
||
| import androidx.lifecycle.LiveData | ||
| import androidx.lifecycle.MutableLiveData | ||
| import androidx.lifecycle.ViewModel | ||
| import androidx.lifecycle.viewModelScope | ||
| import dagger.hilt.android.lifecycle.HiltViewModel | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
| import kotlinx.coroutines.flow.asStateFlow | ||
| import kotlinx.coroutines.launch | ||
| import org.sopt.dosopttemplate.data.entity.auth.AuthInfo | ||
| import org.sopt.dosopttemplate.data.repository.auth.AuthRepository | ||
| import org.sopt.dosopttemplate.util.UiState | ||
| import timber.log.Timber | ||
|
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. log가 아니라 timber를 사용해야 하는 이유가 따로 있나요?? 릴리즈했을 땐 자동으로 사라지는건가여 timber는?? |
||
| import javax.inject.Inject | ||
|
|
||
| @HiltViewModel | ||
| class LoginViewModel @Inject constructor( | ||
| private val authRepository: AuthRepository, | ||
| ) : ViewModel() { | ||
|
|
||
| private val _signInResult = MutableLiveData<UiState<AuthInfo>>() | ||
| val signInResult: LiveData<UiState<AuthInfo>> = _signInResult | ||
| private val _signInState = MutableStateFlow<UiState<AuthInfo>>(UiState.Loading) | ||
| val signInState get() = _signInState.asStateFlow() | ||
|
|
||
| fun signIn(username: String, password: String) { | ||
| viewModelScope.launch { | ||
| authRepository.postSignInInfo( | ||
| username = username, | ||
| password = password, | ||
| ).onSuccess { authInfo -> | ||
| _signInResult.value = UiState.Success(authInfo) | ||
| _signInState.value = UiState.Success(authInfo) | ||
| }.onFailure { throwable -> | ||
| _signInResult.value = throwable.message?.let { UiState.Failure(it) } | ||
| Timber.e(throwable.message) | ||
|
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. 다들 TImber를 엄청 좋아하시는구만 |
||
| } | ||
| } | ||
| } | ||
|
|
||
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.
launchIn은 어떤 기능을 하는건가요?? 못보던거 같은데
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.
저도 궁금해여