Skip to content

Commit

Permalink
[MOD] #303 유저 프로필 스크랩 구현 로직 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
sxunea committed Jan 9, 2024
1 parent 52fd46c commit 77db0a1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class ProfileActivity : BindingActivity<ActivityProfileBinding>(R.layout.activit
private fun initAdapter() {
adapter = ProfileCourseAdapter(onScrapButtonClick = { courseId, scrapTF ->
viewModel.postCourseScrap(courseId = courseId, scrapTF = scrapTF)
viewModel.saveScrapCourseData(courseId = courseId, scrapTF = scrapTF)
}, onCourseItemClick = { courseId ->
navigateToCourseDetail(courseId)
}).also { adapter ->
Expand Down Expand Up @@ -106,10 +105,11 @@ class ProfileActivity : BindingActivity<ActivityProfileBinding>(R.layout.activit
}

is UiStateV2.Success -> {
viewModel.scrapCourseData.value?.let { scrapCourseData ->
scrapCourseData.let { data ->
adapter.updateCourseItem(courseId = data.first, scrapTF = data.second)
}
state.data?.let { it ->
adapter.updateCourseItem(
courseId = it.publicCourseId.toInt(),
scrapTF = it.scrapTF
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.runnect.runnect.data.dto.request.RequestPostCourseScrap
import com.runnect.runnect.data.dto.response.ResponsePostScrap
import com.runnect.runnect.domain.entity.UserProfile
import com.runnect.runnect.domain.repository.CourseRepository
import com.runnect.runnect.domain.repository.UserRepository
Expand All @@ -21,22 +22,14 @@ class ProfileViewModel @Inject constructor(
) :
ViewModel() {

private val _courseScrapState = MutableLiveData<UiStateV2<Unit?>>()
val courseScrapState: LiveData<UiStateV2<Unit?>>
private val _courseScrapState = MutableLiveData<UiStateV2<ResponsePostScrap?>>()
val courseScrapState: LiveData<UiStateV2<ResponsePostScrap?>>
get() = _courseScrapState

private val _userProfileState = MutableLiveData<UiStateV2<UserProfile>>()
val userProfileState: LiveData<UiStateV2<UserProfile>>
get() = _userProfileState

private val _scrapCourseData = MutableLiveData<Pair<Int, Boolean>>()

val scrapCourseData: LiveData<Pair<Int, Boolean>>
get() = _scrapCourseData

fun saveScrapCourseData(courseId: Int, scrapTF: Boolean) {
_scrapCourseData.value = Pair(courseId, scrapTF)
}

fun getUserProfile(userId: Int) {
viewModelScope.launch {
Expand All @@ -62,7 +55,6 @@ class ProfileViewModel @Inject constructor(
fun postCourseScrap(courseId: Int, scrapTF: Boolean) {
viewModelScope.launch {
_courseScrapState.value = UiStateV2.Loading

courseRepository.postCourseScrap(
RequestPostCourseScrap(
publicCourseId = courseId, scrapTF = scrapTF.toString()
Expand Down

0 comments on commit 77db0a1

Please sign in to comment.