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/#146] 장소 상세 페이지 사용자 정보 가져오기 API 붙이기 #151

Merged
merged 3 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -110,10 +110,10 @@ fun PlaceDetailRoute(
is UiState.Success -> (state.userEntity as UiState.Success<UserEntity>).data
else -> UserEntity(
userId = -1,
userEmail = "[email protected]",
userProfileUrl = "https://avatars.githubusercontent.com/u/93641814?v=4",
userName = "안세홍",
userRegion = "성북구"
userEmail = "",
userProfileUrl = "",
userName = "",
userRegion = ""
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.navigation.toRoute
import com.spoony.spoony.core.state.UiState
import com.spoony.spoony.domain.repository.AuthRepository
import com.spoony.spoony.domain.repository.PostRepository
import com.spoony.spoony.presentation.placeDetail.model.toModel
import com.spoony.spoony.presentation.placeDetail.navigation.PlaceDetail
Expand All @@ -21,6 +22,7 @@ import timber.log.Timber
@HiltViewModel
class PlaceDetailViewModel @Inject constructor(
private val postRepository: PostRepository,
private val authRepository: AuthRepository,
savedStateHandle: SavedStateHandle
) : ViewModel() {
private var _state: MutableStateFlow<PlaceDetailState> = MutableStateFlow(PlaceDetailState())
Expand All @@ -38,6 +40,27 @@ class PlaceDetailViewModel @Inject constructor(
userId = UiState.Success(data = postArgs.userId)
)
getPost(postArgs.postId, postArgs.userId)
getUserInfo(postArgs.userId)
}

private fun getUserInfo(userId: Int) {
viewModelScope.launch {
authRepository.getUserInfo(userId = userId)
.onSuccess { response ->
_state.update {
it.copy(
userEntity = UiState.Success(response)
)
}
}
.onFailure {
_state.update {
it.copy(
userEntity = UiState.Failure("사용자 정보 조회 실패")
)
}
}
}
}

private fun getPost(postId: Int, userId: Int) {
Expand Down
Loading