Skip to content

Commit baa4572

Browse files
committed
Refactor: syncError 노출 및 ObserveRoutineSyncErrorUseCase 추가
1 parent 836b342 commit baa4572

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

data/src/main/java/com/threegap/bitnagil/data/routine/repositoryImpl/RoutineRepositoryImpl.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import kotlinx.coroutines.SupervisorJob
1919
import kotlinx.coroutines.channels.BufferOverflow
2020
import kotlinx.coroutines.flow.Flow
2121
import kotlinx.coroutines.flow.MutableSharedFlow
22+
import kotlinx.coroutines.flow.SharedFlow
23+
import kotlinx.coroutines.flow.asSharedFlow
2224
import kotlinx.coroutines.flow.debounce
2325
import kotlinx.coroutines.flow.emitAll
2426
import kotlinx.coroutines.flow.filterNotNull
@@ -41,6 +43,8 @@ class RoutineRepositoryImpl @Inject constructor(
4143
private val mutex = Mutex()
4244
private val pendingChangesByDate = mutableMapOf<String, MutableMap<String, RoutineCompletionInfo>>()
4345
private val originalStatesByDate = mutableMapOf<String, MutableMap<String, RoutineCompletionInfo>>()
46+
private val _syncError = MutableSharedFlow<Unit>(extraBufferCapacity = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST)
47+
override val syncError: SharedFlow<Unit> = _syncError.asSharedFlow()
4448
private val syncTrigger = MutableSharedFlow<Unit>(
4549
extraBufferCapacity = 1,
4650
onBufferOverflow = BufferOverflow.DROP_OLDEST,
@@ -105,6 +109,7 @@ class RoutineRepositoryImpl @Inject constructor(
105109
val syncRequest = RoutineCompletionInfos(routineCompletionInfos = actualChanges.values.toList())
106110
routineRemoteDataSource.syncRoutineCompletion(syncRequest.toDto())
107111
.onFailure {
112+
_syncError.emit(Unit)
108113
val range = routineLocalDataSource.lastFetchRange ?: return@onFailure
109114
fetchAndSave(range.first, range.second)
110115
}

domain/src/main/java/com/threegap/bitnagil/domain/routine/repository/RoutineRepository.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import com.threegap.bitnagil.domain.routine.model.RoutineEditInfo
66
import com.threegap.bitnagil.domain.routine.model.RoutineRegisterInfo
77
import com.threegap.bitnagil.domain.routine.model.RoutineSchedule
88
import kotlinx.coroutines.flow.Flow
9+
import kotlinx.coroutines.flow.SharedFlow
910

1011
interface RoutineRepository {
12+
val syncError: SharedFlow<Unit>
1113
fun observeWeeklyRoutines(startDate: String, endDate: String): Flow<RoutineSchedule>
1214
suspend fun applyRoutineToggle(dateKey: String, routineId: String, completionInfo: RoutineCompletionInfo)
1315
suspend fun getRoutine(routineId: String): Result<Routine>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.threegap.bitnagil.domain.routine.usecase
2+
3+
import com.threegap.bitnagil.domain.routine.repository.RoutineRepository
4+
import kotlinx.coroutines.flow.Flow
5+
import javax.inject.Inject
6+
7+
class ObserveRoutineSyncErrorUseCase @Inject constructor(
8+
private val routineRepository: RoutineRepository,
9+
) {
10+
operator fun invoke(): Flow<Unit> = routineRepository.syncError
11+
}

0 commit comments

Comments
 (0)