@@ -8,8 +8,6 @@ import com.threegap.bitnagil.domain.emotion.usecase.GetEmotionChangeEventFlowUse
88import com.threegap.bitnagil.domain.onboarding.usecase.GetOnBoardingRecommendRoutineEventFlowUseCase
99import com.threegap.bitnagil.domain.routine.model.RoutineCompletion
1010import com.threegap.bitnagil.domain.routine.model.RoutineCompletionInfo
11- import com.threegap.bitnagil.domain.routine.usecase.DeleteRoutineByDayUseCase
12- import com.threegap.bitnagil.domain.routine.usecase.DeleteRoutineUseCase
1311import com.threegap.bitnagil.domain.routine.usecase.FetchWeeklyRoutinesUseCase
1412import com.threegap.bitnagil.domain.routine.usecase.RoutineCompletionUseCase
1513import com.threegap.bitnagil.domain.user.usecase.FetchUserProfileUseCase
@@ -20,7 +18,6 @@ import com.threegap.bitnagil.presentation.home.model.HomeSideEffect
2018import com.threegap.bitnagil.presentation.home.model.HomeState
2119import com.threegap.bitnagil.presentation.home.model.RoutineUiModel
2220import com.threegap.bitnagil.presentation.home.model.RoutinesUiModel
23- import com.threegap.bitnagil.presentation.home.model.toRoutineByDayDeletion
2421import com.threegap.bitnagil.presentation.home.model.toUiModel
2522import com.threegap.bitnagil.presentation.home.util.getCurrentWeekDays
2623import dagger.hilt.android.lifecycle.HiltViewModel
@@ -42,8 +39,6 @@ class HomeViewModel @Inject constructor(
4239 private val fetchUserProfileUseCase : FetchUserProfileUseCase ,
4340 private val fetchTodayEmotionUseCase : FetchTodayEmotionUseCase ,
4441 private val routineCompletionUseCase : RoutineCompletionUseCase ,
45- private val deleteRoutineUseCase : DeleteRoutineUseCase ,
46- private val deleteRoutineByDayUseCase : DeleteRoutineByDayUseCase ,
4742 private val getWriteRoutineEventFlowUseCase : GetWriteRoutineEventFlowUseCase ,
4843 private val getEmotionChangeEventFlowUseCase : GetEmotionChangeEventFlowUseCase ,
4944 private val getOnBoardingRecommendRoutineEventFlowUseCase : GetOnBoardingRecommendRoutineEventFlowUseCase ,
@@ -63,7 +58,7 @@ class HomeViewModel @Inject constructor(
6358 observeRoutineUpdates()
6459 fetchWeeklyRoutines(container.stateFlow.value.currentWeeks)
6560 fetchUserProfile()
66- getMyEmotion (container.stateFlow.value.selectedDate)
61+ fetchTodayEmotion (container.stateFlow.value.selectedDate)
6762 }
6863
6964 override suspend fun SimpleSyntax <HomeState , HomeSideEffect >.reduceState (
@@ -111,90 +106,12 @@ class HomeViewModel @Inject constructor(
111106 updateSubRoutine(state, intent.routineId, intent.subRoutineId, intent.isCompleted)
112107 }
113108
114- is HomeIntent .DeleteRoutineOptimistically -> {
115- val updatedRoutinesByDate = state.routines.routinesByDate.mapValues { (_, routineList) ->
116- routineList.filterNot { it.routineId == intent.routineId }
117- }
118-
119- state.copy(
120- routines = RoutinesUiModel (routinesByDate = updatedRoutinesByDate),
121- showDeleteConfirmDialog = false ,
122- deletingRoutine = null ,
123- routineDetailsBottomSheetVisible = false ,
124- selectedRoutine = null ,
125- )
126- }
127-
128- is HomeIntent .RestoreRoutinesAfterDeleteFailure -> {
129- state.copy(routines = intent.backupRoutines)
130- }
131-
132- is HomeIntent .ConfirmRoutineDeletion -> null
133-
134- is HomeIntent .ShowRoutineDetailsBottomSheet -> {
135- state.copy(
136- routineDetailsBottomSheetVisible = true ,
137- selectedRoutine = intent.routine,
138- )
139- }
140-
141- is HomeIntent .HideRoutineDetailsBottomSheet -> {
142- state.copy(
143- routineDetailsBottomSheetVisible = false ,
144- selectedRoutine = null ,
145- )
146- }
147-
148- is HomeIntent .ShowDeleteConfirmDialog -> {
149- state.copy(
150- showDeleteConfirmDialog = true ,
151- deletingRoutine = intent.routine,
152- )
153- }
154-
155- is HomeIntent .HideDeleteConfirmDialog -> {
156- state.copy(
157- showDeleteConfirmDialog = false ,
158- deletingRoutine = null ,
159- )
160- }
161-
162- is HomeIntent .DeleteRoutineByDayOptimistically -> {
163- val dateKey = intent.performedDate
164- val updatedRoutinesByDate = state.routines.routinesByDate.toMutableMap()
165- val routinesForDate = updatedRoutinesByDate[dateKey]?.toMutableList()
166-
167- if (routinesForDate != null ) {
168- updatedRoutinesByDate[dateKey] = routinesForDate.filterNot {
169- it.routineId == intent.routineId
170- }
171- }
172-
173- state.copy(
174- routines = RoutinesUiModel (routinesByDate = updatedRoutinesByDate),
175- showDeleteConfirmDialog = false ,
176- deletingRoutine = null ,
177- routineDetailsBottomSheetVisible = false ,
178- selectedRoutine = null ,
179- )
180- }
181-
182- is HomeIntent .RestoreRoutinesAfterDeleteByDayFailure -> {
183- state.copy(routines = intent.backupRoutines)
184- }
185-
186- is HomeIntent .ConfirmRoutineByDayDeletion -> null
187-
188109 is HomeIntent .LoadTodayEmotion -> {
189110 state.copy(todayEmotion = intent.emotion)
190111 }
191112
192113 is HomeIntent .OnRegisterEmotionClick -> {
193- if (state.myEmotion == null ) {
194- sendSideEffect(HomeSideEffect .NavigateToEmotion )
195- } else {
196- sendSideEffect(HomeSideEffect .ShowToastWithIcon (" 선택한 감정 구슬이 이미 반영되었어요." ))
197- }
114+ sendSideEffect(HomeSideEffect .NavigateToEmotion )
198115 null
199116 }
200117
@@ -207,11 +124,6 @@ class HomeViewModel @Inject constructor(
207124 sendSideEffect(HomeSideEffect .ShowToast (" 루틴 완료 상태 저장에 실패했어요.\n 다시 시도해 주세요." ))
208125 null
209126 }
210-
211- is HomeIntent .NavigateToEditRoutine -> {
212- sendSideEffect(HomeSideEffect .NavigateToEditRoutine (intent.routineId))
213- null
214- }
215127 }
216128 return newState
217129 }
@@ -228,7 +140,7 @@ class HomeViewModel @Inject constructor(
228140 viewModelScope.launch {
229141 getEmotionChangeEventFlowUseCase().collect {
230142 val currentDate = LocalDate .now()
231- getMyEmotion (currentDate)
143+ fetchTodayEmotion (currentDate)
232144 }
233145 }
234146 }
@@ -301,7 +213,7 @@ class HomeViewModel @Inject constructor(
301213 }
302214 }
303215
304- private fun getMyEmotion (currentDate : LocalDate ) {
216+ private fun fetchTodayEmotion (currentDate : LocalDate ) {
305217 sendIntent(HomeIntent .UpdateLoading (true ))
306218 viewModelScope.launch {
307219 fetchTodayEmotionUseCase(currentDate.toString()).fold(
@@ -494,52 +406,4 @@ class HomeViewModel @Inject constructor(
494406 },
495407 )
496408 }
497-
498- fun deleteRoutine (routineId : String ) {
499- val currentRoutines = container.stateFlow.value.routines
500- sendIntent(HomeIntent .DeleteRoutineOptimistically (routineId))
501-
502- viewModelScope.launch {
503- deleteRoutineUseCase(routineId).fold(
504- onSuccess = {
505- sendIntent(HomeIntent .ConfirmRoutineDeletion (routineId))
506- },
507- onFailure = { error ->
508- Log .e(" HomeViewModel" , " 루틴 삭제 실패: ${error.message} " )
509- sendIntent(HomeIntent .RestoreRoutinesAfterDeleteFailure (currentRoutines))
510- },
511- )
512- }
513- }
514-
515- fun deleteRoutineByDay (routineUiModel : RoutineUiModel ) {
516- val currentRoutines = container.stateFlow.value.routines
517- val performedDate = container.stateFlow.value.selectedDate.toString()
518-
519- sendIntent(
520- HomeIntent .DeleteRoutineByDayOptimistically (
521- routineId = routineUiModel.routineId,
522- performedDate = performedDate,
523- ),
524- )
525-
526- viewModelScope.launch {
527- val routineByDayDeletion = routineUiModel.toRoutineByDayDeletion(performedDate)
528-
529- deleteRoutineByDayUseCase(routineByDayDeletion).fold(
530- onSuccess = {
531- sendIntent(
532- HomeIntent .ConfirmRoutineByDayDeletion (
533- routineId = routineUiModel.routineId,
534- performedDate = performedDate,
535- ),
536- )
537- },
538- onFailure = {
539- Log .e(" HomeViewModel" , " 루틴 삭제 실패: ${it.message} " )
540- sendIntent(HomeIntent .RestoreRoutinesAfterDeleteByDayFailure (currentRoutines))
541- },
542- )
543- }
544- }
545409}
0 commit comments