diff --git a/app/src/main/java/com/runnect/runnect/presentation/profile/ProfileActivity.kt b/app/src/main/java/com/runnect/runnect/presentation/profile/ProfileActivity.kt index c92d55148..21d30c6d7 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/profile/ProfileActivity.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/profile/ProfileActivity.kt @@ -36,7 +36,6 @@ class ProfileActivity : BindingActivity(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 -> @@ -106,10 +105,11 @@ class ProfileActivity : BindingActivity(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 + ) } } diff --git a/app/src/main/java/com/runnect/runnect/presentation/profile/ProfileViewModel.kt b/app/src/main/java/com/runnect/runnect/presentation/profile/ProfileViewModel.kt index 08a9721f4..b518cc418 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/profile/ProfileViewModel.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/profile/ProfileViewModel.kt @@ -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 @@ -21,22 +22,14 @@ class ProfileViewModel @Inject constructor( ) : ViewModel() { - private val _courseScrapState = MutableLiveData>() - val courseScrapState: LiveData> + private val _courseScrapState = MutableLiveData>() + val courseScrapState: LiveData> get() = _courseScrapState private val _userProfileState = MutableLiveData>() val userProfileState: LiveData> get() = _userProfileState - private val _scrapCourseData = MutableLiveData>() - - val scrapCourseData: LiveData> - get() = _scrapCourseData - - fun saveScrapCourseData(courseId: Int, scrapTF: Boolean) { - _scrapCourseData.value = Pair(courseId, scrapTF) - } fun getUserProfile(userId: Int) { viewModelScope.launch { @@ -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()