Skip to content

Commit 6f82d71

Browse files
authored
Merge pull request #167 from YAPP-Github/refactor/#166-report-dto-serialization
[Refactor/#166] Report 관련 Dto의 Enum class 직렬화 전략을 변경합니다.
2 parents f2d0af7 + 07b3fb9 commit 6f82d71

File tree

8 files changed

+27
-59
lines changed

8 files changed

+27
-59
lines changed

data/src/main/java/com/threegap/bitnagil/data/report/model/request/ReportRequestDto.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ data class ReportRequestDto(
1212
@SerialName("reportContent")
1313
val reportContent: String,
1414
@SerialName("reportCategory")
15-
val reportCategory: String,
15+
val reportCategory: ReportCategory,
1616
@SerialName("reportImageUrls")
1717
val reportImageUrls: List<String>,
1818
@SerialName("reportLocation")
@@ -27,7 +27,7 @@ fun Report.toDto(): ReportRequestDto {
2727
return ReportRequestDto(
2828
reportTitle = this.title,
2929
reportContent = this.content,
30-
reportCategory = ReportCategory.toString(this.category),
30+
reportCategory = this.category,
3131
reportImageUrls = this.imageUrls,
3232
reportLocation = this.address,
3333
latitude = this.latitude,

data/src/main/java/com/threegap/bitnagil/data/report/model/response/ReportDetailDto.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ class ReportDetailDto(
1212
@SerialName("reportDate")
1313
val reportDate: String,
1414
@SerialName("reportStatus")
15-
val reportStatus: String,
15+
val reportStatus: ReportStatus,
1616
@SerialName("reportTitle")
1717
val reportTitle: String,
1818
@SerialName("reportContent")
1919
val reportContent: String,
2020
@SerialName("reportCategory")
21-
val reportCategory: String,
21+
val reportCategory: ReportCategory,
2222
@SerialName("reportLocation")
2323
val reportLocation: String,
2424
@SerialName("reportImageUrls")
@@ -29,10 +29,10 @@ fun ReportDetailDto.toDomain(id: String?): ReportDetail =
2929
ReportDetail(
3030
id = id ?: "",
3131
date = LocalDate.parse(this.reportDate),
32-
status = ReportStatus.fromString(this.reportStatus),
32+
status = this.reportStatus,
3333
title = this.reportTitle,
3434
content = this.reportContent,
35-
category = ReportCategory.fromString(this.reportCategory),
35+
category = this.reportCategory,
3636
address = this.reportLocation,
3737
imageUrls = this.reportImageUrls,
3838
)

data/src/main/java/com/threegap/bitnagil/data/report/model/response/ReportItemDto.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ data class ReportItemDto(
1111
@SerialName("reportId")
1212
val reportId: Int,
1313
@SerialName("reportStatus")
14-
val reportStatus: String,
14+
val reportStatus: ReportStatus,
1515
@SerialName("reportTitle")
1616
val reportTitle: String,
1717
@SerialName("reportCategory")
18-
val reportCategory: String,
18+
val reportCategory: ReportCategory,
1919
@SerialName("reportLocation")
2020
val reportLocation: String,
2121
@SerialName("reportImageUrl")
@@ -25,9 +25,9 @@ data class ReportItemDto(
2525
fun ReportItemDto.toDomain(): ReportItem =
2626
ReportItem(
2727
id = this.reportId,
28-
status = ReportStatus.fromString(this.reportStatus),
28+
status = this.reportStatus,
2929
title = this.reportTitle,
30-
category = ReportCategory.fromString(this.reportCategory),
30+
category = this.reportCategory,
3131
address = this.reportLocation,
3232
imageUrl = this.reportImageUrl,
3333
)

domain/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
plugins {
22
alias(libs.plugins.bitnagil.kotlin)
3+
alias(libs.plugins.kotlin.serialization)
34
}
45

56
dependencies {
7+
implementation(libs.kotlinx.serialization.json)
68
implementation(libs.kotlinx.coroutines.core)
79
implementation(libs.javax.inject)
810
testImplementation(libs.junit)
Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,12 @@
11
package com.threegap.bitnagil.domain.report.model
22

3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
36
enum class ReportCategory {
47
TRANSPORTATION,
58
LIGHTING,
69
WATERFACILITY,
710
AMENITY,
811
;
9-
10-
companion object {
11-
fun fromString(value: String): ReportCategory {
12-
return when (value) {
13-
"TRANSPORTATION" -> TRANSPORTATION
14-
"LIGHTING" -> LIGHTING
15-
"WATERFACILITY" -> WATERFACILITY
16-
"AMENITY" -> AMENITY
17-
else -> throw IllegalArgumentException("Invalid ReportCategory value: $value")
18-
}
19-
}
20-
21-
fun toString(value: ReportCategory): String {
22-
return when (value) {
23-
TRANSPORTATION -> "TRANSPORTATION"
24-
LIGHTING -> "LIGHTING"
25-
WATERFACILITY -> "WATERFACILITY"
26-
AMENITY -> "AMENITY"
27-
}
28-
}
29-
}
3012
}
Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,11 @@
11
package com.threegap.bitnagil.domain.report.model
22

3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
36
enum class ReportStatus {
4-
Pending,
5-
InProgress,
6-
Completed,
7+
PENDING,
8+
IN_PROGRESS,
9+
COMPLETED,
710
;
8-
9-
companion object {
10-
fun fromString(value: String): ReportStatus {
11-
return when (value) {
12-
"PENDING" -> Pending
13-
"IN_PROGRESS" -> InProgress
14-
"COMPLETED" -> Completed
15-
else -> throw IllegalArgumentException("Invalid ReportStatus value: $value")
16-
}
17-
}
18-
19-
fun toString(value: ReportStatus): String {
20-
return when (value) {
21-
Pending -> "PENDING"
22-
InProgress -> "IN_PROGRESS"
23-
Completed -> "COMPLETED"
24-
}
25-
}
26-
}
2711
}

presentation/src/main/java/com/threegap/bitnagil/presentation/reportdetail/model/ReportProcess.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ enum class ReportProcess(
1313
companion object {
1414
fun fromDomain(status: ReportStatus): ReportProcess {
1515
return when (status) {
16-
ReportStatus.Pending -> Reported
17-
ReportStatus.InProgress -> Progress
18-
ReportStatus.Completed -> Complete
16+
ReportStatus.PENDING -> Reported
17+
ReportStatus.IN_PROGRESS -> Progress
18+
ReportStatus.COMPLETED -> Complete
1919
}
2020
}
2121
}

presentation/src/main/java/com/threegap/bitnagil/presentation/reporthistory/model/ReportProcess.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ enum class ReportProcess(
1414
companion object {
1515
fun fromDomain(status: ReportStatus): ReportProcess {
1616
return when (status) {
17-
ReportStatus.Pending -> Reported
18-
ReportStatus.InProgress -> Progress
19-
ReportStatus.Completed -> Complete
17+
ReportStatus.PENDING -> Reported
18+
ReportStatus.IN_PROGRESS -> Progress
19+
ReportStatus.COMPLETED -> Complete
2020
}
2121
}
2222
}

0 commit comments

Comments
 (0)