Skip to content

Commit

Permalink
[MERGE] #314 디벨롭 브랜치와의 머지
Browse files Browse the repository at this point in the history
  • Loading branch information
leeeha committed Feb 10, 2024
1 parent da67bfb commit b8852f2
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.runnect.runnect.data.repository

import com.runnect.runnect.data.dto.request.RequestPutMyDrawCourse
import com.runnect.runnect.data.dto.MyDrawCourse
import com.runnect.runnect.domain.entity.MyScrapCourse
import com.runnect.runnect.data.dto.response.ResponsePutMyDrawCourse
import com.runnect.runnect.data.dto.response.toMyDrawCourse
import com.runnect.runnect.data.source.remote.RemoteStorageDataSource
import com.runnect.runnect.domain.entity.MyDrawCourse
import com.runnect.runnect.domain.repository.StorageRepository
import retrofit2.Response
import javax.inject.Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,20 @@ import com.runnect.runnect.data.dto.request.RequestPostCourseScrap
import com.runnect.runnect.data.dto.request.RequestPostPublicCourse
import com.runnect.runnect.data.dto.request.RequestPostRunningHistory
import com.runnect.runnect.data.dto.request.RequestPutMyDrawCourse
import com.runnect.runnect.data.dto.response.*
import com.runnect.runnect.data.dto.response.ResponseGetCourseDetail
import com.runnect.runnect.data.dto.response.ResponseGetDiscoverMarathon
import com.runnect.runnect.data.dto.response.ResponseGetDiscoverPick
import com.runnect.runnect.data.dto.response.ResponseGetDiscoverRecommend
import com.runnect.runnect.data.dto.response.ResponseGetDiscoverSearch
import com.runnect.runnect.data.dto.response.ResponseGetMyDrawCourse
import com.runnect.runnect.data.dto.response.ResponseGetMyDrawDetail
import com.runnect.runnect.data.dto.response.ResponseGetMyScrapCourse
import com.runnect.runnect.data.dto.response.ResponsePatchPublicCourse
import com.runnect.runnect.data.dto.response.ResponsePostDiscoverUpload
import com.runnect.runnect.data.dto.response.ResponsePostMyDrawCourse
import com.runnect.runnect.data.dto.response.ResponsePostMyHistory
import com.runnect.runnect.data.dto.response.ResponsePostScrap
import com.runnect.runnect.data.dto.response.ResponsePutMyDrawCourse
import com.runnect.runnect.data.dto.response.base.BaseResponse
import okhttp3.MultipartBody
import okhttp3.RequestBody
Expand Down Expand Up @@ -60,8 +73,7 @@ interface CourseService {

//보관함 내가 그린 코스 가져오기
@GET("/api/course/user")
suspend fun getDrawCourseList(
): Response<ResponseGetMyDrawCourse>
suspend fun getDrawCourseList(): BaseResponse<ResponseGetMyDrawCourse>

//보관함 스크랩 코스 가져오기
@GET("/api/scrap/user")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.runnect.runnect.domain.repository

import com.runnect.runnect.data.dto.MyDrawCourse
import com.runnect.runnect.domain.entity.MyScrapCourse
import com.runnect.runnect.data.dto.request.RequestPutMyDrawCourse
import com.runnect.runnect.data.dto.response.ResponsePutMyDrawCourse
import com.runnect.runnect.domain.entity.MyDrawCourse
import retrofit2.Response

interface StorageRepository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class StorageMyDrawFragment :
}

private fun observeStorageState() {
viewModel.myDrawCoursesGetState.observe(viewLifecycleOwner) {
viewModel.myDrawCourseGetState.observe(viewLifecycleOwner) {
when (it) {
UiState.Empty -> hideLoadingBar()
UiState.Loading -> showLoadingBar()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class StorageScrapFragment :
}

private fun setupMyScrapCourseGetStateObserver() {
viewModel.myScrapCoursesGetState.observe(viewLifecycleOwner) { state ->
viewModel.myScrapCourseGetState.observe(viewLifecycleOwner) { state ->
when (state) {
is UiStateV2.Loading -> {
showLoadingProgressBar()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.runnect.runnect.data.dto.MyDrawCourse
import com.runnect.runnect.domain.entity.MyScrapCourse
import com.runnect.runnect.data.dto.request.RequestPostCourseScrap
import com.runnect.runnect.data.dto.request.RequestPutMyDrawCourse
import com.runnect.runnect.data.dto.response.ResponsePostScrap
import com.runnect.runnect.domain.entity.MyDrawCourse
import com.runnect.runnect.domain.repository.CourseRepository
import com.runnect.runnect.domain.repository.StorageRepository
import com.runnect.runnect.presentation.state.UiState
Expand All @@ -24,21 +24,21 @@ class StorageViewModel @Inject constructor(
private val storageRepository: StorageRepository,
private val courseRepository: CourseRepository
) : ViewModel() {
private val _myDrawCoursesDeleteState = MutableLiveData<UiState>()
val myDrawCourseDeleteState: LiveData<UiState>
get() = _myDrawCoursesDeleteState

private val _myDrawCoursesGetState = MutableLiveData<UiState>(UiState.Empty)
val myDrawCoursesGetState: LiveData<UiState>
get() = _myDrawCoursesGetState
private val _myDrawCourseGetState = MutableLiveData<UiState>(UiState.Empty)
val myDrawCourseGetState: LiveData<UiState>
get() = _myDrawCourseGetState

private var _myDrawCourses = mutableListOf<MyDrawCourse>()
val myDrawCourses: List<MyDrawCourse>
get() = _myDrawCourses

private val _myScrapCoursesGetState = MutableLiveData<UiStateV2<List<MyScrapCourse>>?>()
val myScrapCoursesGetState: LiveData<UiStateV2<List<MyScrapCourse>>?>
get() = _myScrapCoursesGetState
private val _myDrawCourseDeleteState = MutableLiveData<UiState>()
val myDrawCourseDeleteState: LiveData<UiState>
get() = _myDrawCourseDeleteState

private val _myScrapCourseGetState = MutableLiveData<UiStateV2<List<MyScrapCourse>>?>()
val myScrapCourseGetState: LiveData<UiStateV2<List<MyScrapCourse>>?>
get() = _myScrapCourseGetState

private val _courseScrapState = MutableLiveData<UiStateV2<ResponsePostScrap?>>()
val courseScrapState: LiveData<UiStateV2<ResponsePostScrap?>>
Expand All @@ -54,24 +54,24 @@ class StorageViewModel @Inject constructor(
fun getMyDrawList() {
viewModelScope.launch {
runCatching {
_myDrawCoursesGetState.value = UiState.Loading
_myDrawCourseGetState.value = UiState.Loading
storageRepository.getMyDrawCourse()
}.onSuccess {
_myDrawCourses = (it.getOrNull() ?: emptyList()).toMutableList()
Timber.tag(ContentValues.TAG).d("데이터 수신 완료")
_myDrawCoursesGetState.value = UiState.Success
_myDrawCourseGetState.value = UiState.Success
}.onFailure {
Timber.tag(ContentValues.TAG).d("onFailure 메세지 : $it")
errorMessage.value = it.message
_myDrawCoursesGetState.value = UiState.Failure
_myDrawCourseGetState.value = UiState.Failure
}
}
}

fun deleteMyDrawCourse() {
viewModelScope.launch {
runCatching {
_myDrawCoursesDeleteState.value = UiState.Loading
_myDrawCourseDeleteState.value = UiState.Loading
storageRepository.deleteMyDrawCourse(
RequestPutMyDrawCourse(
courseIdList = itemsToDelete
Expand All @@ -81,35 +81,35 @@ class StorageViewModel @Inject constructor(
Timber.tag(ContentValues.TAG).d("삭제 성공입니다")
_myDrawCourses =
_myDrawCourses.filter { !itemsToDelete.contains(it.courseId) }.toMutableList()
_myDrawCoursesDeleteState.value = UiState.Success
_myDrawCourseDeleteState.value = UiState.Success

}.onFailure {
Timber.tag(ContentValues.TAG).d("실패했고 문제는 다음과 같습니다 $it")
_myDrawCoursesDeleteState.value = UiState.Failure
_myDrawCourseDeleteState.value = UiState.Failure
}
}
}

fun getMyScrapCourses() {
viewModelScope.launch {
_myScrapCoursesGetState.value = UiStateV2.Loading
_myScrapCourseGetState.value = UiStateV2.Loading

storageRepository.getMyScrapCourse()
.onSuccess { response ->
.onSuccess { response ->
if (response == null) {
_myScrapCoursesGetState.value =
_myScrapCourseGetState.value =
UiStateV2.Failure("MY SCRAP COURSE DATA IS NULL")
return@launch
}

Timber.d("MY SCRAP COURSE GET SUCCESS")
_myScrapCoursesGetState.value = UiStateV2.Success(response)
_myScrapCourseGetState.value = UiStateV2.Success(response)
itemSize.value = response.size
}
.onFailure { t ->
Timber.e("MY SCRAP COURSE GET FAIL")
Timber.e("${t.message}")
_myScrapCoursesGetState.value = UiStateV2.Failure(t.message.toString())
_myScrapCourseGetState.value = UiStateV2.Failure(t.message.toString())
}
}
}
Expand All @@ -122,13 +122,14 @@ class StorageViewModel @Inject constructor(
RequestPostCourseScrap(
publicCourseId = id, scrapTF = scrapTF.toString()
)
).onSuccess { response ->
_courseScrapState.value = UiStateV2.Success(response)
}
.onFailure { t ->
Timber.e("${t.message}")
_courseScrapState.value = UiStateV2.Failure(t.message.toString())
}
)
.onSuccess { response ->
_courseScrapState.value = UiStateV2.Success(response)
}
.onFailure { t ->
Timber.e("${t.message}")
_courseScrapState.value = UiStateV2.Failure(t.message.toString())
}
}
}

Expand Down

0 comments on commit b8852f2

Please sign in to comment.