Skip to content

Commit 434bbb9

Browse files
committed
Refactor: SubRoutine 모델 및 관련 로직 변경
- SubRoutine -> SubRoutineUiModel로 클래스명 변경 - 도메인 모델을 UI 모델로 변환하는 확장 함수 추가 - WriteRoutineViewModel에서 변경된 SubRoutineUiModel을 사용하도록 수정
1 parent a64ea30 commit 434bbb9

4 files changed

Lines changed: 23 additions & 27 deletions

File tree

presentation/src/main/java/com/threegap/bitnagil/presentation/writeroutine/WriteRoutineViewModel.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ import com.threegap.bitnagil.domain.writeroutine.model.RepeatDay
88
import com.threegap.bitnagil.domain.writeroutine.model.RoutineUpdateType
99
import com.threegap.bitnagil.domain.writeroutine.usecase.EditRoutineUseCase
1010
import com.threegap.bitnagil.domain.writeroutine.usecase.RegisterRoutineUseCase
11-
import com.threegap.bitnagil.presentation.common.extension.displayTitle
1211
import com.threegap.bitnagil.presentation.writeroutine.contract.WriteRoutineSideEffect
1312
import com.threegap.bitnagil.presentation.writeroutine.contract.WriteRoutineState
1413
import com.threegap.bitnagil.presentation.writeroutine.model.Date
1514
import com.threegap.bitnagil.presentation.writeroutine.model.Day
1615
import com.threegap.bitnagil.presentation.writeroutine.model.RepeatType
1716
import com.threegap.bitnagil.presentation.writeroutine.model.SelectableDay
18-
import com.threegap.bitnagil.presentation.writeroutine.model.SubRoutine
17+
import com.threegap.bitnagil.presentation.writeroutine.model.SubRoutineUiModel
1918
import com.threegap.bitnagil.presentation.writeroutine.model.Time
2019
import com.threegap.bitnagil.presentation.writeroutine.model.WriteRoutineType
2120
import com.threegap.bitnagil.presentation.writeroutine.model.navarg.WriteRoutineScreenArg
21+
import com.threegap.bitnagil.presentation.writeroutine.model.toUiModel
2222
import dagger.assisted.Assisted
2323
import dagger.assisted.AssistedFactory
2424
import dagger.assisted.AssistedInject
@@ -46,7 +46,7 @@ class WriteRoutineViewModel @AssistedInject constructor(
4646
)
4747

4848
private var routineId: String? = null
49-
private var oldSubRoutines: List<SubRoutine> = listOf()
49+
private var oldSubRoutineUiModels: List<SubRoutineUiModel> = listOf()
5050

5151
init {
5252
val navigationArg = writeRoutineArg
@@ -131,7 +131,7 @@ class WriteRoutineViewModel @AssistedInject constructor(
131131
}
132132
getRecommendRoutineUseCase(recommendRoutineId).fold(
133133
onSuccess = { routine ->
134-
oldSubRoutines = routine.subRoutines.map { SubRoutine.fromDomainRecommendSubRoutine(it) }
134+
oldSubRoutineUiModels = routine.subRoutines.map { it.toUiModel() }
135135

136136
reduce {
137137
state.copy(
@@ -142,9 +142,9 @@ class WriteRoutineViewModel @AssistedInject constructor(
142142
startDate = Date.now(),
143143
endDate = Date.now(),
144144
subRoutineNames = listOf(
145-
oldSubRoutines.getOrNull(0)?.name ?: "",
146-
oldSubRoutines.getOrNull(1)?.name ?: "",
147-
oldSubRoutines.getOrNull(2)?.name ?: "",
145+
oldSubRoutineUiModels.getOrNull(0)?.name ?: "",
146+
oldSubRoutineUiModels.getOrNull(1)?.name ?: "",
147+
oldSubRoutineUiModels.getOrNull(2)?.name ?: "",
148148
),
149149
loading = false,
150150
recommendedRoutineType = routine.category,

presentation/src/main/java/com/threegap/bitnagil/presentation/writeroutine/contract/WriteRoutineState.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,8 @@ data class WriteRoutineState(
9797
null -> ""
9898
}
9999

100-
val periodText: String get() {
101-
return "${startDate.toYearShrinkageFormattedString()} ~ ${endDate.toYearShrinkageFormattedString()}"
102-
}
100+
val periodText: String
101+
get() = "${startDate.toYearShrinkageFormattedString()} ~ ${endDate.toYearShrinkageFormattedString()}"
103102

104103
val startTimeText: String
105104
get() = if (selectAllTime) "하루종일" else startTime?.let { "${it.toAmPmFormattedString()}부터 시작" } ?: ""

presentation/src/main/java/com/threegap/bitnagil/presentation/writeroutine/model/SubRoutine.kt

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.threegap.bitnagil.presentation.writeroutine.model
2+
3+
import com.threegap.bitnagil.domain.recommendroutine.model.RecommendSubRoutine
4+
5+
data class SubRoutineUiModel(
6+
val id: String,
7+
val name: String,
8+
)
9+
10+
internal fun RecommendSubRoutine.toUiModel(): SubRoutineUiModel =
11+
SubRoutineUiModel(
12+
id = id.toString(),
13+
name = name,
14+
)

0 commit comments

Comments
 (0)