-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
148 additions
and
35 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
10 changes: 5 additions & 5 deletions
10
domain/src/main/kotlin/co/orange/domain/entity/response/AddressModel.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,11 @@ | ||
package co.orange.domain.entity.response | ||
|
||
data class AddressModel( | ||
val addressId: Long, | ||
val addressId: Long?, | ||
val name: String?, | ||
val zipCode: String, | ||
val type: String, | ||
val address: String, | ||
val detailAddress: String, | ||
val zipCode: String?, | ||
val type: String?, | ||
val address: String?, | ||
val detailAddress: String?, | ||
val phone: String?, | ||
) |
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
52 changes: 43 additions & 9 deletions
52
presentation/src/main/java/co/orange/presentation/setting/delivery/DeliveryViewModel.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,21 +1,55 @@ | ||
package co.orange.presentation.setting.delivery | ||
|
||
import androidx.lifecycle.ViewModel | ||
import co.orange.domain.entity.response.AddressInfoModel | ||
import androidx.lifecycle.viewModelScope | ||
import co.orange.core.state.UiState | ||
import co.orange.domain.entity.response.AddressModel | ||
import co.orange.domain.repository.SettingRepository | ||
import co.orange.presentation.address.AddressActivity.Companion.DEFAULT_ID | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableSharedFlow | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.SharedFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class DeliveryViewModel | ||
@Inject | ||
constructor( | ||
// private val feedRepository: FeedRepository, | ||
private val settingRepository: SettingRepository, | ||
) : ViewModel() { | ||
val mockAddressModel = | ||
AddressInfoModel( | ||
"김상호", | ||
"04567", | ||
"서울특벌시 성동구 성수이로 137 107동 903호", | ||
"010-3259-0327", | ||
) | ||
var addressId: Long = DEFAULT_ID | ||
|
||
private val _getUserAddressState = MutableStateFlow<UiState<AddressModel>>(UiState.Empty) | ||
val getUserAddressState: StateFlow<UiState<AddressModel>> = _getUserAddressState | ||
|
||
private val _deleteAddressResult = MutableSharedFlow<Boolean>() | ||
val deleteAddressResult: SharedFlow<Boolean> = _deleteAddressResult | ||
|
||
fun getUserAddressFromServer() { | ||
viewModelScope.launch { | ||
settingRepository.getUserAddress() | ||
.onSuccess { | ||
it.addressId?.let { addressId = it } | ||
_getUserAddressState.value = UiState.Success(it) | ||
} | ||
.onFailure { | ||
_getUserAddressState.value = UiState.Failure(it.message.orEmpty()) | ||
} | ||
} | ||
} | ||
|
||
fun deleteUserAddressFromServer() { | ||
viewModelScope.launch { | ||
settingRepository.deleteUserAddress(addressId) | ||
.onSuccess { | ||
_deleteAddressResult.emit(true) | ||
} | ||
.onFailure { | ||
_deleteAddressResult.emit(false) | ||
} | ||
} | ||
} | ||
} |
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