Skip to content

Commit

Permalink
feat/#196 : 프로필 수정시, 해당 이미지를 storage에 저장
Browse files Browse the repository at this point in the history
* datastore에 저장되는 값은 storage에서 받아온 url 입니다.
  • Loading branch information
shinythinking committed Dec 3, 2024
1 parent c0bd6e3 commit 530a03e
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.boostcamp.mapisode.mypage.R
import com.boostcamp.mapisode.mypage.intent.ProfileEditIntent
import com.boostcamp.mapisode.mypage.sideeffect.ProfileEditSideEffect
import com.boostcamp.mapisode.mypage.state.ProfileEditState
import com.boostcamp.mapisode.storage.StorageRepository
import com.boostcamp.mapisode.ui.base.BaseViewModel
import com.boostcamp.mapisode.user.UserRepository
import dagger.hilt.android.lifecycle.HiltViewModel
Expand All @@ -15,6 +16,7 @@ import javax.inject.Inject

@HiltViewModel
class ProfileEditViewModel @Inject constructor(
private val storageRepository: StorageRepository,
private val userRepository: UserRepository,
private val userPreferenceDataStore: UserPreferenceDataStore,
) : BaseViewModel<ProfileEditIntent, ProfileEditState, ProfileEditSideEffect>(ProfileEditState()) {
Expand Down Expand Up @@ -80,6 +82,7 @@ class ProfileEditViewModel @Inject constructor(
private fun editClick() {
try {
viewModelScope.launch {
updateProfileUrl(getStorageUrl())
storeInUserPreferenceDataStore()
storeInUserRepository()
navigateToMypage()
Expand All @@ -89,6 +92,17 @@ class ProfileEditViewModel @Inject constructor(
}
}

private suspend fun getStorageUrl(): String {
try {
return storageRepository.uploadSingleImageToStorage(
imageUri = currentState.profileUrl,
uid = currentState.uid,
)
} catch (e: Exception) {
throw e
}
}

private suspend fun storeInUserPreferenceDataStore() {
viewModelScope.launch {
with(userPreferenceDataStore) {
Expand Down

0 comments on commit 530a03e

Please sign in to comment.