diff --git a/app/src/main/java/com/runnect/runnect/data/dto/response/ResponseGetMyDrawCourse.kt b/app/src/main/java/com/runnect/runnect/data/dto/response/ResponseGetMyDrawCourse.kt index 5440638c9..7d9776e6d 100644 --- a/app/src/main/java/com/runnect/runnect/data/dto/response/ResponseGetMyDrawCourse.kt +++ b/app/src/main/java/com/runnect/runnect/data/dto/response/ResponseGetMyDrawCourse.kt @@ -1,50 +1,53 @@ package com.runnect.runnect.data.dto.response +import com.runnect.runnect.domain.entity.MyDrawCourse import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable data class ResponseGetMyDrawCourse( - @SerialName("data") - val `data`: Data, - @SerialName("message") - val message: String, - @SerialName("status") - val status: Int, - @SerialName("success") - val success: Boolean, + @SerialName("courses") + val courses: List, + @SerialName("user") + val user: User, ) { @Serializable - data class Data( - @SerialName("courses") - val courses: List, - @SerialName("user") - val user: User, + data class Course( + @SerialName("createdAt") + val createdAt: String, + @SerialName("departure") + val departure: Departure, + @SerialName("id") + val id: Int, + @SerialName("image") + val image: String, + @SerialName("title") + val title: String ) { @Serializable - data class Course( - @SerialName("createdAt") - val createdAt: String, - @SerialName("departure") - val departure: Departure, - @SerialName("id") - val id: Int, - @SerialName("image") - val image: String, - ) { - @Serializable - data class Departure( - @SerialName("city") - val city: String, - @SerialName("region") - val region: String, - ) - } + data class Departure( + @SerialName("city") + val city: String, + @SerialName("region") + val region: String, + ) + } - @Serializable - data class User( - @SerialName("id") - val id: Int, + @Serializable + data class User( + @SerialName("id") + val id: Int, + ) +} + +fun ResponseGetMyDrawCourse.toMyDrawCourse(): List { + return this.courses.map { + MyDrawCourse( + courseId = it.id, + image = it.image, + city = it.departure.city, + region = it.departure.region, + title = it.title ) } } \ No newline at end of file diff --git a/app/src/main/java/com/runnect/runnect/data/dto/response/ResponseGetMyDrawDetail.kt b/app/src/main/java/com/runnect/runnect/data/dto/response/ResponseGetMyDrawDetail.kt index 94199641c..6ac2709bf 100644 --- a/app/src/main/java/com/runnect/runnect/data/dto/response/ResponseGetMyDrawDetail.kt +++ b/app/src/main/java/com/runnect/runnect/data/dto/response/ResponseGetMyDrawDetail.kt @@ -22,38 +22,40 @@ data class ResponseGetMyDrawDetail( @SerialName("user") val user: User, ) { + + @Serializable + data class User( + @SerialName("userId") + val id: Int, + ) @Serializable data class Course( + @SerialName("id") + val id: Int, @SerialName("createdAt") val createdAt: String, - @SerialName("departure") - val departure: Departure, + @SerialName("path") + val path: List>, @SerialName("distance") val distance: Float, - @SerialName("id") - val id: Int, @SerialName("image") val image: String, - @SerialName("path") - val path: List>, + @SerialName("title") + val title: String, + @SerialName("departure") + val departure: Departure, ) { @Serializable data class Departure( - @SerialName("city") - val city: String, - @SerialName("name") - val name: String, @SerialName("region") val region: String, + @SerialName("city") + val city: String, @SerialName("town") val town: String, + @SerialName("name") + val name: String, ) } - - @Serializable - data class User( - @SerialName("id") - val id: Int, - ) } } \ No newline at end of file diff --git a/app/src/main/java/com/runnect/runnect/data/repository/StorageRepositoryImpl.kt b/app/src/main/java/com/runnect/runnect/data/repository/StorageRepositoryImpl.kt index 2f0cf5201..38e8cd1d5 100644 --- a/app/src/main/java/com/runnect/runnect/data/repository/StorageRepositoryImpl.kt +++ b/app/src/main/java/com/runnect/runnect/data/repository/StorageRepositoryImpl.kt @@ -1,34 +1,20 @@ package com.runnect.runnect.data.repository -import com.runnect.runnect.data.dto.MyDrawCourse import com.runnect.runnect.data.dto.MyScrapCourse import com.runnect.runnect.data.dto.request.RequestPutMyDrawCourse -import com.runnect.runnect.data.dto.response.ResponseGetMyDrawCourse import com.runnect.runnect.data.dto.response.ResponseGetMyScrapCourse 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 class StorageRepositoryImpl @Inject constructor(private val remoteStorageDataSource: RemoteStorageDataSource) : StorageRepository { - override suspend fun getMyDrawCourse(): MutableList { - return changeMyDrawData( - data = remoteStorageDataSource.getMyDrawCourse().body()!!.data.courses - ).toMutableList() - } - - private fun changeMyDrawData(data: List): List { - val changedData = data.map { - MyDrawCourse( - courseId = it.id, - image = it.image, - city = it.departure.city, - region = it.departure.region - ) - } - return changedData + override suspend fun getMyDrawCourse(): Result?> = runCatching{ + remoteStorageDataSource.getMyDrawCourse().data?.toMyDrawCourse() } override suspend fun deleteMyDrawCourse(deleteCourseList: RequestPutMyDrawCourse): Response { diff --git a/app/src/main/java/com/runnect/runnect/data/service/CourseService.kt b/app/src/main/java/com/runnect/runnect/data/service/CourseService.kt index 64a8225ad..e55f85792 100644 --- a/app/src/main/java/com/runnect/runnect/data/service/CourseService.kt +++ b/app/src/main/java/com/runnect/runnect/data/service/CourseService.kt @@ -62,7 +62,7 @@ interface CourseService { //보관함 내가 그린 코스 가져오기 @GET("/api/course/user") suspend fun getCourseList( - ): Response + ): BaseResponse //보관함 스크랩 코스 가져오기 @GET("/api/scrap/user") diff --git a/app/src/main/java/com/runnect/runnect/data/source/remote/RemoteStorageDataSource.kt b/app/src/main/java/com/runnect/runnect/data/source/remote/RemoteStorageDataSource.kt index 1444323bb..107175ff3 100644 --- a/app/src/main/java/com/runnect/runnect/data/source/remote/RemoteStorageDataSource.kt +++ b/app/src/main/java/com/runnect/runnect/data/source/remote/RemoteStorageDataSource.kt @@ -5,11 +5,12 @@ import com.runnect.runnect.data.dto.request.RequestPutMyDrawCourse import com.runnect.runnect.data.dto.response.ResponseGetMyDrawCourse import com.runnect.runnect.data.dto.response.ResponseGetMyScrapCourse import com.runnect.runnect.data.dto.response.ResponsePutMyDrawCourse +import com.runnect.runnect.data.dto.response.base.BaseResponse import retrofit2.Response import javax.inject.Inject class RemoteStorageDataSource @Inject constructor(private val courseService: CourseService) { - suspend fun getMyDrawCourse(): Response = + suspend fun getMyDrawCourse(): BaseResponse = courseService.getCourseList() suspend fun deleteMyDrawCourse(deleteCourseList: RequestPutMyDrawCourse): Response = diff --git a/app/src/main/java/com/runnect/runnect/data/dto/MyDrawCourse.kt b/app/src/main/java/com/runnect/runnect/domain/entity/MyDrawCourse.kt similarity index 77% rename from app/src/main/java/com/runnect/runnect/data/dto/MyDrawCourse.kt rename to app/src/main/java/com/runnect/runnect/domain/entity/MyDrawCourse.kt index c29940ee3..bc8f91e36 100644 --- a/app/src/main/java/com/runnect/runnect/data/dto/MyDrawCourse.kt +++ b/app/src/main/java/com/runnect/runnect/domain/entity/MyDrawCourse.kt @@ -1,5 +1,4 @@ -package com.runnect.runnect.data.dto - +package com.runnect.runnect.domain.entity import android.os.Parcelable import kotlinx.android.parcel.Parcelize @@ -10,4 +9,5 @@ data class MyDrawCourse( val image: String?, val city: String, val region: String, + val title: String ) : Parcelable \ No newline at end of file diff --git a/app/src/main/java/com/runnect/runnect/domain/repository/StorageRepository.kt b/app/src/main/java/com/runnect/runnect/domain/repository/StorageRepository.kt index 3ab37cd36..fe9996d06 100644 --- a/app/src/main/java/com/runnect/runnect/domain/repository/StorageRepository.kt +++ b/app/src/main/java/com/runnect/runnect/domain/repository/StorageRepository.kt @@ -1,13 +1,13 @@ package com.runnect.runnect.domain.repository -import com.runnect.runnect.data.dto.MyDrawCourse import com.runnect.runnect.data.dto.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 { - suspend fun getMyDrawCourse(): MutableList? + suspend fun getMyDrawCourse(): Result?> suspend fun deleteMyDrawCourse(deleteCourseList: RequestPutMyDrawCourse) : Response suspend fun getMyScrapCourse(): MutableList? } \ No newline at end of file diff --git a/app/src/main/java/com/runnect/runnect/presentation/storage/StorageViewModel.kt b/app/src/main/java/com/runnect/runnect/presentation/storage/StorageViewModel.kt index a93d93224..860bcd6a5 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/storage/StorageViewModel.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/storage/StorageViewModel.kt @@ -5,7 +5,7 @@ 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.MyDrawCourse import com.runnect.runnect.data.dto.MyScrapCourse import com.runnect.runnect.data.dto.request.RequestPostCourseScrap import com.runnect.runnect.data.dto.request.RequestPutMyDrawCourse @@ -49,7 +49,7 @@ class StorageViewModel @Inject constructor( _storageState.value = UiState.Loading storageRepository.getMyDrawCourse() }.onSuccess { - _myDrawCourses = it!! + _myDrawCourses = (it.getOrNull() ?: emptyList()).toMutableList() Timber.tag(ContentValues.TAG).d("데이터 수신 완료") _storageState.value = UiState.Success }.onFailure { diff --git a/app/src/main/java/com/runnect/runnect/presentation/storage/adapter/StorageMyDrawAdapter.kt b/app/src/main/java/com/runnect/runnect/presentation/storage/adapter/StorageMyDrawAdapter.kt index e121289a6..1d0a0a677 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/storage/adapter/StorageMyDrawAdapter.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/storage/adapter/StorageMyDrawAdapter.kt @@ -4,10 +4,9 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.core.view.isVisible -import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView -import com.runnect.runnect.data.dto.MyDrawCourse +import com.runnect.runnect.domain.entity.MyDrawCourse import com.runnect.runnect.databinding.ItemStorageMyDrawBinding import com.runnect.runnect.util.callback.ItemCount import com.runnect.runnect.util.callback.diff.ItemDiffCallback diff --git a/app/src/main/java/com/runnect/runnect/presentation/storage/adapter/StorageScrapAdapter.kt b/app/src/main/java/com/runnect/runnect/presentation/storage/adapter/StorageScrapAdapter.kt index f343da17b..242d03129 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/storage/adapter/StorageScrapAdapter.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/storage/adapter/StorageScrapAdapter.kt @@ -2,10 +2,8 @@ package com.runnect.runnect.presentation.storage.adapter import android.view.LayoutInflater import android.view.ViewGroup -import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView -import com.runnect.runnect.data.dto.MyDrawCourse import com.runnect.runnect.data.dto.MyScrapCourse import com.runnect.runnect.databinding.ItemStorageScrapBinding import com.runnect.runnect.util.callback.ItemCount diff --git a/app/src/main/res/layout/item_storage_my_draw.xml b/app/src/main/res/layout/item_storage_my_draw.xml index 963ae21d9..a7a1d7e25 100644 --- a/app/src/main/res/layout/item_storage_my_draw.xml +++ b/app/src/main/res/layout/item_storage_my_draw.xml @@ -9,7 +9,7 @@ + type="com.runnect.runnect.domain.entity.MyDrawCourse" />