Skip to content

Commit

Permalink
Merge pull request #345 from Runnect/feature/refactor-api-flow-discov…
Browse files Browse the repository at this point in the history
…er-mypage

[REFACTOR] api 로직 수정
  • Loading branch information
dongx0915 authored Apr 30, 2024
2 parents 5661733 + 05fb441 commit 2f2fa5d
Show file tree
Hide file tree
Showing 78 changed files with 1,343 additions and 1,321 deletions.
11 changes: 0 additions & 11 deletions app/src/main/java/com/runnect/runnect/data/dto/LocationData.kt

This file was deleted.

1 change: 0 additions & 1 deletion app/src/main/java/com/runnect/runnect/data/dto/LoginDTO.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.runnect.runnect.data.dto

data class LoginDTO(
val status: Int,
val accessToken: String,
val refreshToken: String,
val email: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ import kotlinx.serialization.Serializable
@Serializable
data class ResponseGetMyDrawCourse(
@SerialName("courses")
val courses: List<Course>,
val courses: List<Course>?,
@SerialName("user")
val user: User,
val user: User?,
) {
@Serializable
data class Course(
@SerialName("createdAt")
val createdAt: String,
val createdAt: String?,
@SerialName("departure")
val departure: Departure,
val departure: Departure?,
@SerialName("id")
val id: Int,
val id: Int?,
@SerialName("image")
val image: String,
val image: String?,
@SerialName("title")
val title: String
val title: String?
) {
@Serializable
data class Departure(
@SerialName("city")
val city: String,
val city: String?,
@SerialName("region")
val region: String,
val region: String?,
)
}

Expand All @@ -41,13 +41,17 @@ data class ResponseGetMyDrawCourse(
}

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
)

return if (this.courses.isNullOrEmpty()) emptyList()
else {
this.courses.map {
MyDrawCourse(
courseId = it.id,
image = it.image,
city = it.departure?.city ?: "", //todo - 예외 처리 논의
region = it.departure?.region ?: "",
title = it.title ?: ""
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,61 +1,49 @@
package com.runnect.runnect.data.dto.response


import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ResponseGetMyDrawDetail(
@SerialName("data")
val data: Data,
@SerialName("message")
val message: String,
@SerialName("status")
val status: Int,
@SerialName("success")
val success: Boolean,
@SerialName("course")
val course: Course,
@SerialName("user")
val user: User,
) {
@Serializable
data class Data(
@SerialName("course")
val course: Course,
@SerialName("user")
val user: User,
) {
data class User(
@SerialName("userId")
val id: Int,
)

@Serializable
data class Course(
@SerialName("id")
val id: Int,
@SerialName("createdAt")
val createdAt: String,
@SerialName("path")
val path: List<List<Double>>,
@SerialName("distance")
val distance: Float,
@SerialName("image")
val image: String,
@SerialName("title")
val title: String,
@SerialName("departure")
val departure: Departure,
) {
@Serializable
data class User(
@SerialName("userId")
val id: Int,
data class Departure(
@SerialName("region")
val region: String,
@SerialName("city")
val city: String,
@SerialName("town")
val town: String,
@SerialName("name")
val name: String,
)
@Serializable
data class Course(
@SerialName("id")
val id: Int,
@SerialName("createdAt")
val createdAt: String,
@SerialName("path")
val path: List<List<Double>>,
@SerialName("distance")
val distance: Float,
@SerialName("image")
val image: String,
@SerialName("title")
val title: String,
@SerialName("departure")
val departure: Departure,
) {
@Serializable
data class Departure(
@SerialName("region")
val region: String,
@SerialName("city")
val city: String,
@SerialName("town")
val town: String,
@SerialName("name")
val name: String,
)
}
}

}
Original file line number Diff line number Diff line change
@@ -1,44 +1,72 @@
package com.runnect.runnect.data.dto.response

import com.runnect.runnect.data.dto.HistoryInfoDTO
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ResponseGetMyHistory(
val `data`: HistoryData,
val message: String,
val status: Int,
val success: Boolean
)
val user: RecordUser,
val records: List<Record>,
) {
@Serializable
data class RecordUser(
@SerialName("userId") val id: Int
)

@Serializable
data class Record(
val courseId: Int,
val createdAt: String,
val departure: Departure,
val distance: Double,
val id: Int,
val image: String,
val pace: String,
val publicCourseId: Int?,
val time: String,
val title: String
)
@Serializable
data class Record(
val courseId: Int,
val createdAt: String,
val departure: Departure,
val distance: Double,
val id: Int,
val image: String,
val pace: String,
val publicCourseId: Int?,
val time: String,
val title: String
) {
@Serializable
data class Departure(
val city: String,
val region: String
)
}

@Serializable
data class Departure(
val city: String,
val region: String
)
fun toHistoryInfoList(): List<HistoryInfoDTO> {
return records.map {
HistoryInfoDTO(
id = it.id,
img = it.image,
title = it.title,
location = "${it.departure.region} ${it.departure.city}",
date = (it.createdAt.split(" ")[0]).replace("-", "."),
distance = it.distance.toString(),
time = timeConvert(it.time),
pace = paceConvert(it.pace)
)
}
}

@Serializable
data class RecordUser(
@SerialName("userId") val id: Int
)

@Serializable
data class HistoryData(
val records: List<Record>,
val user: RecordUser
)
private fun timeConvert(time: String): String {
val hms = time.split(":").toMutableList()
if (hms[0] == "00") {
hms[0] = "0"
}
return "${hms[0]}:${hms[1]}:${hms[2]}"
}

private fun paceConvert(p: String): String {
val pace = p.split(":").toMutableList()
return if (pace[0] == "00") {
pace.removeAt(0)
if (pace[0][0] == '0') {
pace[0] = pace[0][1].toString()
}
"${pace[0]}${pace[1]}"
} else {
"${pace[0]}${pace[1]}${pace[2]}"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
package com.runnect.runnect.data.dto.response

import kotlinx.serialization.Serializable

@Serializable
data class ResponseGetMyStamp(
val `data`: StampData,
val message: String,
val status: Int,
val success: Boolean
)

@Serializable
data class StampData(
val user: StampUser,
val stamps: List<Stamp>,
val user: StampUser
)
) {
@Serializable
data class StampUser(
val id: Int
)

@Serializable
data class Stamp(
val id: String
)
@Serializable
data class Stamp(
val id: String
)

@Serializable
data class StampUser(
val id: Int
)
fun toStampList() = stamps.map { it.id }
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
package com.runnect.runnect.data.dto.response

import com.runnect.runnect.domain.entity.User
import kotlinx.serialization.Serializable

@Serializable
data class ResponseGetUser(
val data: Data,
val message: String,
val status: Int,
val success: Boolean
)
val user: UserResponse,
) {

@Serializable
data class Data(
val user: User
)
@Serializable
data class UserResponse(
val email: String,
val latestStamp: String,
val level: Int,
val levelPercent: Int,
val nickname: String
)

@Serializable
data class User(
val email:String,
val latestStamp: String,
val level: Int,
val levelPercent: Int,
val nickname: String
)
fun toUser(): User {
return User(
email = user.email,
latestStamp = user.latestStamp,
level = user.level,
levelPercent = user.levelPercent,
nickname = user.nickname
)
}
}
Loading

0 comments on commit 2f2fa5d

Please sign in to comment.