Skip to content

Commit

Permalink
[FEAT/#100] 판매 물품 확정 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
Marchbreeze committed Sep 1, 2024
1 parent 18475bf commit 5392c20
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.viewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import co.orange.core.base.BaseActivity
import co.orange.core.extension.setOnSingleClickListener
import co.orange.core.extension.setPriceForm
import co.orange.core.extension.stringOf
import co.orange.core.extension.toast
import co.orange.core.state.UiState
import co.orange.domain.entity.response.SellProductModel
import co.orange.presentation.sell.push.SellPushActivity
import coil.load
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kr.genti.presentation.R
import kr.genti.presentation.databinding.ActivitySellProgressBinding

Expand All @@ -26,8 +33,8 @@ class SellProgressActivity :
initTermBtnListener()
initConfirmBtnListener()
initDateBtnListener()
getIntentInfo()
setIntentUi(viewModel.mockSellInfo)
getProductWithIdFromIntent()
observeGetProductState()
}

private fun initExitBtnListener() {
Expand All @@ -44,7 +51,7 @@ class SellProgressActivity :

private fun initConfirmBtnListener() {
binding.btnConfirmSell.setOnSingleClickListener {
// TODO 구매 요청 서버통신 이후
// TODO 계좌 확인 & 구매 요청 서버통신 이후
SellPushActivity.createIntent(this, -1).apply {
startActivity(this)
}
Expand All @@ -53,20 +60,38 @@ class SellProgressActivity :

private fun initDateBtnListener() {
// TODO 데이트피커 구현
// tvSellDate.text = "2024.06.28"
}

private fun getIntentInfo() {
viewModel.productId = intent.getStringExtra(EXTRA_PRODUCT_ID).orEmpty()
private fun getProductWithIdFromIntent() {
with(viewModel) {
productId = intent.getStringExtra(EXTRA_PRODUCT_ID).orEmpty()
getProductWIthId()
}
}

private fun observeGetProductState() {
viewModel.getProductState.flowWithLifecycle(lifecycle).distinctUntilChanged()
.onEach { state ->
when (state) {
is UiState.Success -> setIntentUi(state.data)
is UiState.Failure -> {
toast(stringOf(R.string.error_msg))
finish()
}

else -> return@onEach
}
}.launchIn(lifecycleScope)
}

private fun setIntentUi(item: SellProductModel) {
with(binding) {
tvSellInfoName.text = item.productName
tvSellInfoOriginPrice.text = item.originPrice.setPriceForm()
tvSellInfoSellPrice.text = item.salePrice.setPriceForm()
// TODO : intent 수정
ivSellProduct.load(R.drawable.mock_img_product)
tvSellDate.text = "2024.06.28"
// TODO
// ivSellProduct.load(R.drawable.mock_img_product)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
package co.orange.presentation.sell.progress

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import co.orange.core.state.UiState
import co.orange.domain.entity.response.SellProductModel
import co.orange.domain.repository.SellRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class SellProgressViewModel
@Inject
constructor(
// private val feedRepository: FeedRepository,
private val sellRepository: SellRepository,
) : ViewModel() {
var productId = ""
var isAccountExist = false

var mockSellInfo =
SellProductModel(
"1102303002",
"딴지 키링 세트",
9000,
7000,
true,
)
private val _getProductState = MutableStateFlow<UiState<SellProductModel>>(UiState.Empty)
val getProductState: StateFlow<UiState<SellProductModel>> = _getProductState

fun getProductWIthId() {
if (productId.isEmpty()) {
_getProductState.value = UiState.Failure(productId)
return
}
_getProductState.value = UiState.Loading
viewModelScope.launch {
sellRepository.getProductToSell(productId)
.onSuccess {
isAccountExist = it.isAddressExist
_getProductState.value = UiState.Success(it)
}
.onFailure {
_getProductState.value = UiState.Failure(it.message.orEmpty())
}
}
}
}

0 comments on commit 5392c20

Please sign in to comment.