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

[MOD] 보관함 - 내가 그린 코스 / 사용자가 설정한 제목이 표시 되도록 수정 #310

Merged
merged 11 commits into from
Feb 7, 2024
Merged
Original file line number Diff line number Diff line change
@@ -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<Course>,
@SerialName("user")
val user: User,
) {
@Serializable
data class Data(
@SerialName("courses")
val courses: List<Course>,
@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<MyDrawCourse> {
return this.courses.map {
MyDrawCourse(
courseId = it.id,
image = it.image,
city = it.departure.city,
region = it.departure.region,
title = it.title
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<Double>>,
@SerialName("distance")
val distance: Float,
@SerialName("id")
val id: Int,
@SerialName("image")
val image: String,
@SerialName("path")
val path: List<List<Double>>,
@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,
)
}
}
Original file line number Diff line number Diff line change
@@ -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<MyDrawCourse> {
return changeMyDrawData(
data = remoteStorageDataSource.getMyDrawCourse().body()!!.data.courses
).toMutableList()
}

private fun changeMyDrawData(data: List<ResponseGetMyDrawCourse.Data.Course>): List<MyDrawCourse> {
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<List<MyDrawCourse>?> = runCatching{
remoteStorageDataSource.getMyDrawCourse().data?.toMyDrawCourse()
}

override suspend fun deleteMyDrawCourse(deleteCourseList: RequestPutMyDrawCourse): Response<ResponsePutMyDrawCourse> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ interface CourseService {
//보관함 내가 그린 코스 가져오기
@GET("/api/course/user")
suspend fun getCourseList(
): Response<ResponseGetMyDrawCourse>
): BaseResponse<ResponseGetMyDrawCourse>

//보관함 스크랩 코스 가져오기
@GET("/api/scrap/user")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResponseGetMyDrawCourse> =
suspend fun getMyDrawCourse(): BaseResponse<ResponseGetMyDrawCourse> =
courseService.getCourseList()

suspend fun deleteMyDrawCourse(deleteCourseList: RequestPutMyDrawCourse): Response<ResponsePutMyDrawCourse> =
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,4 +9,5 @@ data class MyDrawCourse(
val image: String?,
val city: String,
val region: String,
val title: String
) : Parcelable
Original file line number Diff line number Diff line change
@@ -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<MyDrawCourse>?
suspend fun getMyDrawCourse(): Result<List<MyDrawCourse>?>
suspend fun deleteMyDrawCourse(deleteCourseList: RequestPutMyDrawCourse) : Response<ResponsePutMyDrawCourse>
suspend fun getMyScrapCourse(): MutableList<MyScrapCourse>?
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/item_storage_my_draw.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<variable
name="storageItem"
type="com.runnect.runnect.data.dto.MyDrawCourse" />
type="com.runnect.runnect.domain.entity.MyDrawCourse" />

<variable
name="selected"
Expand Down Expand Up @@ -80,7 +80,7 @@
android:fontFamily="@font/pretendard_medium"
android:gravity="center_vertical"
android:maxLength="13"
android:text="@{storageItem.region + ' ' + storageItem.city }"
android:text="@{storageItem.title}"
android:textColor="@color/G1"
app:scale_height="22"
app:scale_textsize="14"
Expand Down
Loading