-
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.
- Loading branch information
1 parent
18475bf
commit 5392c20
Showing
2 changed files
with
62 additions
and
18 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
37 changes: 28 additions & 9 deletions
37
presentation/src/main/java/co/orange/presentation/sell/progress/SellProgressViewModel.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,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()) | ||
} | ||
} | ||
} | ||
} |