Skip to content

Commit

Permalink
[feature] #302 - 페이징 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
hansh0101 committed Jun 20, 2022
1 parent 40f21b7 commit 7792094
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ class ScrapViewModel @Inject constructor(
fun getScrapList(sort: String) {
viewModelScope.launch {
kotlin.runCatching {
scrapListRepository.getScrapList(sort)
if (sort == "id,desc") {
scrapListRepository.fetchDefaultScrapList()
} else {
scrapListRepository.fetchQueryScrapList(sort)
}
}.onSuccess { response ->
_scrapList.value = response.contents
lastPlanId = response.nextCursor
Expand All @@ -50,7 +54,7 @@ class ScrapViewModel @Inject constructor(
fun getEmptyScrapList() {
viewModelScope.launch {
kotlin.runCatching {
scrapListRepository.getEmptyScrapList()
scrapListRepository.fetchEmptyScrapList()
}.onSuccess {
if (_emptyScrapList.value != it.data) {
_emptyScrapList.value = it.data
Expand All @@ -61,6 +65,23 @@ class ScrapViewModel @Inject constructor(
}
}

fun getMoreScrapList(sort: String) {
viewModelScope.launch {
runCatching {
if (sort == "id,desc") {
scrapListRepository.fetchDefaultMoreScrapList(size, lastPlanId)
} else {
scrapListRepository.fetchQueryMoreScrapList(size, lastPlanId, sort)
}
}.onSuccess {
_scrapList.value = scrapList.value?.toMutableList()?.apply { addAll(it.contents) }
lastPlanId = it.nextCursor
}.onFailure {
Timber.e(it)
}
}
}

fun postScrap(planId: Int) {
viewModelScope.launch {
kotlin.runCatching {
Expand Down

0 comments on commit 7792094

Please sign in to comment.