Skip to content

Commit

Permalink
[FEAT/#64] 주소지 삭제 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
Marchbreeze committed Aug 9, 2024
1 parent b33fb8c commit d0fc0c0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class DeliveryActivity : BaseActivity<ActivityDeliveryBinding>(R.layout.activity
initWebBtnListener()
initDeleteBtnListener()
observeUserAddressState()
observeDeleteAddressResult()
}

override fun onResume() {
super.onResume()

viewModel.getUserAddressFromServer()
}

private fun initBackBtnListener() {
Expand All @@ -51,8 +58,9 @@ class DeliveryActivity : BaseActivity<ActivityDeliveryBinding>(R.layout.activity
}

private fun initDeleteBtnListener() {
// TODO
binding.btnDeliveryDelete.setOnSingleClickListener { }
binding.btnDeliveryDelete.setOnSingleClickListener {
viewModel.deleteUserAddressFromServer()
}
}

private fun observeUserAddressState() {
Expand Down Expand Up @@ -82,4 +90,19 @@ class DeliveryActivity : BaseActivity<ActivityDeliveryBinding>(R.layout.activity
}
}.launchIn(lifecycleScope)
}

private fun observeDeleteAddressResult() {
viewModel.deleteAddressResult.flowWithLifecycle(lifecycle).distinctUntilChanged()
.onEach { isSuccess ->
if (isSuccess) {
toast(stringOf(R.string.address_delete_toast))
with(binding) {
btnDeliveryAdd.isVisible = true
layoutDeliveryItem.isVisible = false
}
} else {
toast(stringOf(R.string.error_msg))
}
}.launchIn(lifecycleScope)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ 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
Expand All @@ -23,11 +25,10 @@ class DeliveryViewModel
private val _getUserAddressState = MutableStateFlow<UiState<AddressModel>>(UiState.Empty)
val getUserAddressState: StateFlow<UiState<AddressModel>> = _getUserAddressState

init {
getUserAddressFromServer()
}
private val _deleteAddressResult = MutableSharedFlow<Boolean>()
val deleteAddressResult: SharedFlow<Boolean> = _deleteAddressResult

private fun getUserAddressFromServer() {
fun getUserAddressFromServer() {
viewModelScope.launch {
settingRepository.getUserAddress()
.onSuccess {
Expand All @@ -39,4 +40,16 @@ class DeliveryViewModel
}
}
}

fun deleteUserAddressFromServer() {
viewModelScope.launch {
settingRepository.deleteUserAddress(addressId)
.onSuccess {
_deleteAddressResult.emit(true)
}
.onFailure {
_deleteAddressResult.emit(false)
}
}
}
}
1 change: 1 addition & 0 deletions presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
<string name="address_tv_phone_hint">휴대폰 번호를 입력해주세요</string>
<string name="address_btn_confirm">입력 완료</string>
<string name="address_toast">배송지 입력이 완료되었습니다</string>
<string name="address_delete_toast">배송지가 삭제되었습니다</string>

<string name="btn_mod">수정</string>
<string name="btn_delete">삭제</string>
Expand Down

0 comments on commit d0fc0c0

Please sign in to comment.