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,5 +1,6 @@
package com.runnect.runnect.data.dto.response

import com.runnect.runnect.domain.entity.MyDrawCourse
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand Down Expand Up @@ -31,6 +32,8 @@ data class ResponseGetMyDrawCourse(
val id: Int,
@SerialName("image")
val image: String,
@SerialName("title")
val title: String
) {
@Serializable
data class Departure(
Expand All @@ -47,4 +50,16 @@ data class ResponseGetMyDrawCourse(
val id: Int,
)
}
}

fun List<ResponseGetMyDrawCourse.Data.Course>.toMyDrawCourse(): List<MyDrawCourse> {
return this.map {
MyDrawCourse(
courseId = it.id,
image = it.image,
city = it.departure.city,
region = it.departure.region,
title = it.title
)
}
dongx0915 marked this conversation as resolved.
Show resolved Hide resolved
}
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,22 @@
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
return remoteStorageDataSource.getMyDrawCourse().body()?.let {
Copy link
Collaborator

@sxunea sxunea Jan 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기존 코드이긴 하지만 BaseResponse가 생겼으니 Response 바꾸는 김에 적용하면 더욱 간결할 것 같아요 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sxunea 감사합니다. 수정하였습니다~!

it.data.courses.toMyDrawCourse().toMutableList()
} ?: mutableListOf()
}

override suspend fun deleteMyDrawCourse(deleteCourseList: RequestPutMyDrawCourse): Response<ResponsePutMyDrawCourse> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ interface CourseService {

//코스 업로드
@Multipart
@POST("/api/course/v2")
@POST("/api/course")
suspend fun uploadCourse(
@Part image: MultipartBody.Part,
@Part("courseCreateRequestDto") courseCreateRequestDto: RequestBody,
@Part("data") courseCreateRequestDto: RequestBody,
): Response<ResponsePostMyDrawCourse>
}
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,6 +1,6 @@
package com.runnect.runnect.domain.repository

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.RequestPutMyDrawCourse
import com.runnect.runnect.data.dto.response.ResponsePutMyDrawCourse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ class DrawViewModel @Inject constructor(
)
),
title = courseTitle,
distance = distanceSum.value!!,
departureAddress = departureAddress.value!!, //커스텀의 경우 지금 여기에 들어가는 게 아무것도 없음.
departureName = departureName.value!!
distance = distanceSum.value ?: 0.0f,
departureAddress = departureAddress.value ?: "", //커스텀의 경우 지금 여기에 들어가는 게 아무것도 없음.
departureName = departureName.value ?: ""
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null 처리 기본 값 이대로 지정해도 괜찮을 지 확인 부탁드립니다.
기존엔 하나라도 null이면 runCatching에 잡혀서 onFailure로 빠지고 있더라구요

일단은 임시로 null 처리 해두었습니다.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기본값을 세팅한다는 건 앱을 죽이지 않고 살리겠다는 것인데 포인트는 DrawActivity의 data가 CountDown -> Run 액티비티로 넘어간다는 것입니다. 앱은 안 죽었지만 사용자가 의도했던 것과 다른 코스/출발지 등등으로 세팅되어 RunActivity가 실행되는 것은 의미가 없다고 판단하여

현재 아래와 같이 값에 이상이 있을 경우 토스트 메세지를 띄우고 페이지를 안 넘기게 막아놨습니다.
이와 관련된 논의 스레드입니다.
https://w1670909332-6ay129099.slack.com/archives/C04EXNB86LB/p1703075472448109

                if (courseData.courseId == null || courseData.departure == null || courseData.distance == null) {
                    Toast.makeText(
                        this@DrawActivity,
                        ERROR_COURSE_NULL,
                        Toast.LENGTH_LONG
                    ).show()
                }

null 처리 기본값 지정 시 위의 toast 메세지 로직이 안 먹히게 되어 이 부분은 기본값 없이 두는 게 좋을 것 같습니다.

혹시 더 좋은 의견이 있다면 궁금합니다 :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앱은 안 죽었지만 사용자가 의도했던 것과 다른 코스/출발지 등등으로 세팅되어 RunActivity가 실행되는 것은 의미가 없다고 판단하여

그러면 RunActivity와 같이 올바른 기능 수행이 어려울 때는 페이지를 넘기지 않고, GET과 같은 데이터를 가져와서 ui에 붙이는 통신들(ex. 마라톤 코스 GET)은 기본값을 지정해주는 것으로 이해하면 될까요 ? 앱이 터지지 않는 것도, 의미 있는 사용도 챙기다보니 기준이 좀 모호한 것 같아서요 다른 분들도 생각이 궁금합니다 !

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sxunea

기준이라는 개념보다는 그때그때 상황 보고 기획 단과 논의하여 결정하면 될 것 같습니다! 경우의 수가 다양하니까요

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@unam98 해당 부분 Revert 해두었습니다~!

).toRequestBody()
)
}.onSuccess {
Expand Down
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
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