Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT/#177] 탐색 뷰 사용자 스푼 개수 API 연결 및 장소 상세 떠먹었을 시 스푼 개수 업데이트 #180

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading