-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feat/#36 submit to mypage] 제출 페이지를 마이페이지로 수정
- Loading branch information
Showing
11 changed files
with
290 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 32 additions & 4 deletions
36
feature/projects/src/main/java/com/zucchini/projects/MainViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,39 @@ | ||
package com.zucchini.projects | ||
|
||
import androidx.lifecycle.ViewModel | ||
import com.sample.network.datastore.NetworkPreference | ||
import com.kakao.sdk.user.UserApiClient | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class MainViewModel @Inject constructor( | ||
private val netPreference: NetworkPreference, | ||
) : ViewModel() | ||
class MainViewModel @Inject constructor() : ViewModel() { | ||
|
||
private val _userNickname = MutableStateFlow("") | ||
val userNickname = _userNickname.asStateFlow() | ||
|
||
private val _userEmail = MutableStateFlow("") | ||
val userEmail = _userEmail.asStateFlow() | ||
|
||
private val _userProfile = MutableStateFlow("") | ||
val userProfile = _userProfile.asStateFlow() | ||
|
||
init { | ||
getKakaoUserInfo() | ||
} | ||
|
||
private fun getKakaoUserInfo() { | ||
UserApiClient.instance.me { user, error -> | ||
if (error != null) { | ||
_userNickname.value = "" | ||
_userEmail.value = "" | ||
_userProfile.value = "" | ||
} else if (user != null) { | ||
_userNickname.value = user.kakaoAccount?.profile?.nickname ?: "no nickname" | ||
_userEmail.value = user.kakaoAccount?.email ?: "no email" | ||
_userProfile.value = user.kakaoAccount?.profile?.thumbnailImageUrl ?: "" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
feature/projects/src/main/java/com/zucchini/projects/mypage/MypageViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.zucchini.projects.mypage | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.kakao.sdk.user.UserApiClient | ||
import com.sample.network.datastore.NetworkPreference | ||
import com.zucchini.domain.repository.AuthRepository | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.launch | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class MypageViewModel @Inject constructor( | ||
private val preference: NetworkPreference, | ||
private val authRepository: AuthRepository, | ||
|
||
) : ViewModel() { | ||
|
||
private val _logoutSuccess = MutableStateFlow<Boolean>(false) | ||
val logoutSuccess = _logoutSuccess.asStateFlow() | ||
|
||
private val _withdrawalSuccess = MutableStateFlow<Boolean>(false) | ||
val withdrawalSuccess = _withdrawalSuccess.asStateFlow() | ||
|
||
fun logout() { | ||
viewModelScope.launch { | ||
authRepository.logout(preference.accessToken).onSuccess { | ||
preference.clear() | ||
_logoutSuccess.value = true | ||
}.onFailure { | ||
_logoutSuccess.value = false | ||
Timber.d("failed to logout $it") | ||
} | ||
} | ||
} | ||
|
||
fun withdrawal() { | ||
viewModelScope.launch { | ||
authRepository.withdrawal(preference.accessToken).onSuccess { | ||
preference.clear() | ||
kakaoUnlink() | ||
}.onFailure { | ||
_withdrawalSuccess.value = false | ||
Timber.d("failed to withdrawal") | ||
} | ||
} | ||
} | ||
|
||
private fun kakaoUnlink() { | ||
UserApiClient.instance.unlink { error -> | ||
if (error != null) { | ||
_withdrawalSuccess.value = false | ||
Timber.d("failed to unlink: $error") | ||
} else { | ||
_withdrawalSuccess.value = true | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.