Skip to content

Commit fc35108

Browse files
committed
Refactor: RecommendLevel enum 직렬화 및 관련 로직 변경
1 parent 8839bbb commit fc35108

5 files changed

Lines changed: 37 additions & 23 deletions

File tree

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ data class RecommendedRoutineDto(
1515
@SerialName("recommendedRoutineDescription")
1616
val recommendedRoutineDescription: String,
1717
@SerialName("recommendedRoutineLevel")
18-
val recommendedRoutineLevel: String,
18+
val recommendedRoutineLevel: RecommendLevel,
1919
@SerialName("executionTime")
2020
val executionTime: String,
2121
@SerialName("recommendedRoutineType")
@@ -26,11 +26,11 @@ data class RecommendedRoutineDto(
2626

2727
fun RecommendedRoutineDto.toDomain(): RecommendRoutine =
2828
RecommendRoutine(
29-
id = recommendedRoutineId,
30-
name = recommendedRoutineName,
31-
description = recommendedRoutineDescription,
32-
level = RecommendLevel.fromString(recommendedRoutineLevel),
33-
executionTime = executionTime,
29+
id = this.recommendedRoutineId,
30+
name = this.recommendedRoutineName,
31+
description = this.recommendedRoutineDescription,
32+
level = this.recommendedRoutineLevel,
33+
executionTime = this.executionTime,
3434
recommendedRoutineType = RecommendCategory.fromString(recommendedRoutineType),
35-
recommendSubRoutines = recommendedSubRoutineSearchResult.map { it.toDomain() },
35+
recommendSubRoutines = this.recommendedSubRoutineSearchResult.map { it.toDomain() },
3636
)
Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
package com.threegap.bitnagil.domain.recommendroutine.model
22

3-
enum class RecommendLevel(
4-
val level: String,
5-
val koreanLevel: String,
6-
val displayName: String,
7-
) {
8-
LEVEL1("LEVEL1", "", "가볍게 할 수 있어요"),
9-
LEVEL2("LEVEL2", "", "조금 신경써서 할 수 있어요"),
10-
LEVEL3("LEVEL3", "", "의지를 다 잡고 할 수 있어요"),
11-
;
3+
import kotlinx.serialization.Serializable
124

13-
companion object {
14-
fun fromString(levelName: String): RecommendLevel =
15-
entries.find { it.level == levelName } ?: LEVEL1
16-
}
5+
@Serializable
6+
enum class RecommendLevel {
7+
LEVEL1,
8+
LEVEL2,
9+
LEVEL3,
10+
;
1711
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.threegap.bitnagil.presentation.common.extension
2+
3+
import com.threegap.bitnagil.domain.recommendroutine.model.RecommendLevel
4+
5+
fun RecommendLevel.displayLevel(): String =
6+
when (this) {
7+
RecommendLevel.LEVEL1 -> ""
8+
RecommendLevel.LEVEL2 -> ""
9+
RecommendLevel.LEVEL3 -> ""
10+
}
11+
12+
fun RecommendLevel.displayTitle(): String =
13+
when (this) {
14+
RecommendLevel.LEVEL1 -> "가볍게 할 수 있어요"
15+
RecommendLevel.LEVEL2 -> "조금 신경써서 할 수 있어요"
16+
RecommendLevel.LEVEL3 -> "의지를 다 잡고 할 수 있어요"
17+
}

presentation/src/main/java/com/threegap/bitnagil/presentation/recommendroutine/RecommendRoutineScreen.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import com.threegap.bitnagil.designsystem.component.atom.BitnagilIcon
3232
import com.threegap.bitnagil.designsystem.component.block.BitnagilTopBar
3333
import com.threegap.bitnagil.designsystem.modifier.clickableWithoutRipple
3434
import com.threegap.bitnagil.domain.recommendroutine.model.RecommendCategory
35+
import com.threegap.bitnagil.presentation.common.extension.displayLevel
3536
import com.threegap.bitnagil.presentation.recommendroutine.component.atom.RecommendCategoryChip
3637
import com.threegap.bitnagil.presentation.recommendroutine.component.block.EmotionRecommendRoutineButton
3738
import com.threegap.bitnagil.presentation.recommendroutine.component.block.RecommendRoutineItem
@@ -152,7 +153,7 @@ private fun RecommendRoutineScreen(
152153
.clickableWithoutRipple { onShowDifficultyBottomSheet() },
153154
) {
154155
Text(
155-
text = "난이도 ${uiState.selectedRecommendLevel?.koreanLevel ?: "선택"}",
156+
text = "난이도 ${uiState.selectedRecommendLevel?.displayLevel() ?: "선택"}",
156157
color = BitnagilTheme.colors.coolGray40,
157158
style = BitnagilTheme.typography.body2Medium,
158159
modifier = Modifier.padding(start = 10.dp),

presentation/src/main/java/com/threegap/bitnagil/presentation/recommendroutine/component/template/RecommendLevelBottomSheet.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import com.threegap.bitnagil.designsystem.R
1919
import com.threegap.bitnagil.designsystem.component.atom.BitnagilIcon
2020
import com.threegap.bitnagil.designsystem.modifier.clickableWithoutRipple
2121
import com.threegap.bitnagil.domain.recommendroutine.model.RecommendLevel
22+
import com.threegap.bitnagil.presentation.common.extension.displayLevel
23+
import com.threegap.bitnagil.presentation.common.extension.displayTitle
2224
import kotlinx.coroutines.launch
2325

2426
@OptIn(ExperimentalMaterial3Api::class)
@@ -47,8 +49,8 @@ fun RecommendLevelBottomSheet(
4749
) {
4850
RecommendLevel.entries.forEachIndexed { index, recommendLevel ->
4951
LevelOption(
50-
optionLevel = recommendLevel.koreanLevel,
51-
optionText = recommendLevel.displayName,
52+
optionLevel = recommendLevel.displayLevel(),
53+
optionText = recommendLevel.displayTitle(),
5254
isSelected = selectedRecommendLevel == recommendLevel,
5355
onClick = {
5456
val newLevel = if (selectedRecommendLevel == recommendLevel) null else recommendLevel

0 commit comments

Comments
 (0)