Skip to content

Commit

Permalink
[mod] : #283 BaseResponse로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
dongx0915 committed Jan 16, 2024
1 parent 6685b7b commit ac4d6e8
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,42 @@ 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,
@SerialName("title")
val title: String
) {
@Serializable
data class Departure(
@SerialName("city")
val city: String,
@SerialName("region")
val region: String,
)
}

@Serializable
data class User(
@SerialName("id")
val id: Int,
data class Departure(
@SerialName("city")
val city: String,
@SerialName("region")
val region: String,
)
}

@Serializable
data class User(
@SerialName("id")
val id: Int,
)
}

fun List<ResponseGetMyDrawCourse.Data.Course>.toMyDrawCourse(): List<MyDrawCourse> {
return this.map {
fun ResponseGetMyDrawCourse.toMyDrawCourse(): List<MyDrawCourse> {
return this.courses.map {
MyDrawCourse(
courseId = it.id,
image = it.image,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import javax.inject.Inject

class StorageRepositoryImpl @Inject constructor(private val remoteStorageDataSource: RemoteStorageDataSource) :
StorageRepository {
override suspend fun getMyDrawCourse(): MutableList<MyDrawCourse> {
return remoteStorageDataSource.getMyDrawCourse().body()?.let {
it.data.courses.toMyDrawCourse().toMutableList()
} ?: mutableListOf()
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,13 +1,13 @@
package com.runnect.runnect.domain.repository

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
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 @@ -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

0 comments on commit ac4d6e8

Please sign in to comment.