Skip to content

Commit

Permalink
[FEAT/#177] 탐색 뷰 사용자 스푼 개수 API 연결 및 장소 상세 떠먹었을 시 스푼 개수 업데이트
Browse files Browse the repository at this point in the history
  • Loading branch information
Roel4990 committed Jan 24, 2025
1 parent f05452d commit 7ebe42c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ fun ExploreRoute(
else -> 0
}

LaunchedEffect(Unit) {
viewModel.getSpoonAccount()
}

val categoryList = when (state.categoryList) {
is UiState.Success -> (state.categoryList as? UiState.Success<ImmutableList<CategoryEntity>>)?.data ?: persistentListOf()
else -> persistentListOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.spoony.spoony.presentation.explore
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.spoony.spoony.core.state.UiState
import com.spoony.spoony.core.util.USER_ID
import com.spoony.spoony.domain.repository.AuthRepository
import com.spoony.spoony.domain.repository.ExploreRepository
import com.spoony.spoony.presentation.explore.model.toModel
import com.spoony.spoony.presentation.explore.type.SortingOption
Expand All @@ -16,7 +18,8 @@ import kotlinx.coroutines.launch

@HiltViewModel
class ExploreViewModel @Inject constructor(
private val exploreRepository: ExploreRepository
private val exploreRepository: ExploreRepository,
private val authRepository: AuthRepository
) : ViewModel() {
private var _state: MutableStateFlow<ExploreState> = MutableStateFlow(ExploreState())
val state: StateFlow<ExploreState>
Expand Down Expand Up @@ -47,6 +50,19 @@ class ExploreViewModel @Inject constructor(
}
}

fun getSpoonAccount() {
viewModelScope.launch {
authRepository.getSpoonCount(userId = USER_ID)
.onSuccess { response ->
_state.update {
it.copy(
spoonCount = UiState.Success(response)
)
}
}
}
}

fun getFeedList() {
viewModelScope.launch {
exploreRepository.getFeedList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ class PlaceDetailViewModel @Inject constructor(
.onSuccess {
_state.update {
it.copy(
isScooped = true
isScooped = true,
spoonCount = when (val spoonState = it.spoonCount) {
is UiState.Success -> UiState.Success(spoonState.data - 1)
else -> spoonState
}
)
}
}
Expand Down

0 comments on commit 7ebe42c

Please sign in to comment.