Skip to content

Commit 8839bbb

Browse files
committed
Refactor: DTO의 Enum 클래스에 직렬화 적용
- `RecommendedRoutineType`, `EmotionMarbleType`, `DayOfWeek` Enum 클래스에 `@Serializable` 어노테이션을 추가하여 직렬화를 적용합니다.
1 parent 96fe033 commit 8839bbb

7 files changed

Lines changed: 37 additions & 44 deletions

File tree

data/src/main/java/com/threegap/bitnagil/data/recommendroutine/model/response/RecommendRoutinesDto.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ data class RecommendRoutinesDto(
1111
@SerialName("recommendedRoutines")
1212
val recommendedRoutinesByCategory: Map<String, List<RecommendedRoutineDto>>,
1313
@SerialName("emotionMarbleType")
14-
val emotionMarbleType: String?,
14+
val emotionMarbleType: EmotionMarbleType?,
1515
)
1616

1717
fun RecommendRoutinesDto.toDomain(): RecommendRoutines =
1818
RecommendRoutines(
1919
recommendRoutinesByCategory = this.recommendedRoutinesByCategory.map { (categoryString, routines) ->
2020
RecommendCategory.fromString(categoryString) to routines.map { it.toDomain() }
2121
}.toMap(),
22-
emotionMarbleType = this.emotionMarbleType?.let { EmotionMarbleType.valueOf(it) },
22+
emotionMarbleType = this.emotionMarbleType,
2323
)

data/src/main/java/com/threegap/bitnagil/data/routine/model/response/RoutineDto.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ data class RoutineDto(
1313
@SerialName("routineName")
1414
val routineName: String,
1515
@SerialName("repeatDay")
16-
val repeatDay: List<String>,
16+
val repeatDay: List<DayOfWeek>,
1717
@SerialName("executionTime")
1818
val executionTime: String,
1919
@SerialName("routineDate")
@@ -25,7 +25,7 @@ data class RoutineDto(
2525
@SerialName("subRoutineCompleteYn")
2626
val subRoutineCompleteYn: List<Boolean>,
2727
@SerialName("recommendedRoutineType")
28-
val recommendedRoutineType: String?,
28+
val recommendedRoutineType: RecommendedRoutineType?,
2929
@SerialName("routineDeletedYn")
3030
val routineDeletedYn: Boolean,
3131
@SerialName("routineStartDate")
@@ -38,13 +38,13 @@ fun RoutineDto.toDomain(): Routine =
3838
Routine(
3939
id = this.routineId,
4040
name = this.routineName,
41-
repeatDays = this.repeatDay.map { DayOfWeek.fromString(it) },
41+
repeatDays = this.repeatDay.map { it },
4242
executionTime = this.executionTime,
4343
routineDate = this.routineDate,
4444
isCompleted = this.routineCompleteYn,
4545
subRoutineNames = this.subRoutineNames,
4646
subRoutineCompletionStates = this.subRoutineCompleteYn,
47-
recommendedRoutineType = RecommendedRoutineType.fromString(this.recommendedRoutineType),
47+
recommendedRoutineType = this.recommendedRoutineType,
4848
isDeleted = routineDeletedYn,
4949
startDate = this.routineStartDate,
5050
endDate = this.routineEndDate,

domain/src/main/java/com/threegap/bitnagil/domain/recommendroutine/model/EmotionMarbleType.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.threegap.bitnagil.domain.recommendroutine.model
22

3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
36
enum class EmotionMarbleType {
47
CALM,
58
VITALITY,
Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.threegap.bitnagil.domain.routine.model
22

3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
36
enum class DayOfWeek {
47
MONDAY,
58
TUESDAY,
@@ -9,35 +12,4 @@ enum class DayOfWeek {
912
SATURDAY,
1013
SUNDAY,
1114
;
12-
13-
private fun toKoreanShort(): String =
14-
when (this) {
15-
MONDAY -> ""
16-
TUESDAY -> ""
17-
WEDNESDAY -> ""
18-
THURSDAY -> ""
19-
FRIDAY -> ""
20-
SATURDAY -> ""
21-
SUNDAY -> ""
22-
}
23-
24-
companion object {
25-
fun fromString(value: String): DayOfWeek =
26-
when (value) {
27-
"MONDAY" -> MONDAY
28-
"TUESDAY" -> TUESDAY
29-
"WEDNESDAY" -> WEDNESDAY
30-
"THURSDAY" -> THURSDAY
31-
"FRIDAY" -> FRIDAY
32-
"SATURDAY" -> SATURDAY
33-
"SUNDAY" -> SUNDAY
34-
else -> throw IllegalArgumentException("Unknown value: $value")
35-
}
36-
37-
fun List<DayOfWeek>.formatRepeatDays(): String {
38-
if (this.isEmpty()) return "x"
39-
return this.sortedBy { it.ordinal }
40-
.joinToString(", ") { it.toKoreanShort() }
41-
}
42-
}
4315
}
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.threegap.bitnagil.domain.routine.model
22

3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
36
enum class RecommendedRoutineType {
47
PERSONALIZED,
58
OUTING,
@@ -9,9 +12,4 @@ enum class RecommendedRoutineType {
912
GROW,
1013
OUTING_REPORT,
1114
;
12-
13-
companion object {
14-
fun fromString(categoryName: String?): RecommendedRoutineType? =
15-
RecommendedRoutineType.entries.find { it.name == categoryName }
16-
}
1715
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.threegap.bitnagil.presentation.common.extension
2+
3+
import com.threegap.bitnagil.domain.routine.model.DayOfWeek
4+
5+
fun DayOfWeek.displayTitle(): String =
6+
when (this) {
7+
DayOfWeek.MONDAY -> ""
8+
DayOfWeek.TUESDAY -> ""
9+
DayOfWeek.WEDNESDAY -> ""
10+
DayOfWeek.THURSDAY -> ""
11+
DayOfWeek.FRIDAY -> ""
12+
DayOfWeek.SATURDAY -> ""
13+
DayOfWeek.SUNDAY -> ""
14+
}
15+
16+
fun List<DayOfWeek>.displayTitle(): String {
17+
if (this.isEmpty()) return "x"
18+
return this.sortedBy { it.ordinal }
19+
.joinToString(", ") { it.displayTitle() }
20+
}

presentation/src/main/java/com/threegap/bitnagil/presentation/routinelist/component/template/RoutineDetailsCard.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import com.threegap.bitnagil.designsystem.R
2222
import com.threegap.bitnagil.designsystem.component.atom.BitnagilIcon
2323
import com.threegap.bitnagil.designsystem.component.atom.BitnagilIconButton
2424
import com.threegap.bitnagil.domain.routine.model.DayOfWeek
25-
import com.threegap.bitnagil.domain.routine.model.DayOfWeek.Companion.formatRepeatDays
25+
import com.threegap.bitnagil.presentation.common.extension.displayTitle
2626
import com.threegap.bitnagil.presentation.routinelist.model.RoutineUiModel
2727
import com.threegap.bitnagil.presentation.routinelist.model.getColor
2828
import com.threegap.bitnagil.presentation.routinelist.model.getIcon
@@ -132,7 +132,7 @@ fun RoutineDetailsCard(
132132
verticalArrangement = Arrangement.spacedBy(2.dp),
133133
) {
134134
Text(
135-
text = "반복: ${routine.repeatDay.formatRepeatDays()}",
135+
text = "반복: ${routine.repeatDay.displayTitle()}",
136136
color = BitnagilTheme.colors.coolGray40,
137137
style = infoTextStyle,
138138
)

0 commit comments

Comments
 (0)