Skip to content

Commit cb8e5bf

Browse files
committed
refactor/#137 : 불필요한 유즈케이스 제거로 인한 레포지토리 인터페이스 사용 변경
1 parent a644235 commit cb8e5bf

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

feature/history/src/main/java/com/yapp/feature/history/previous/PreviousHistoryViewModel.kt

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ import androidx.lifecycle.viewModelScope
55
import com.yapp.core.common.android.record
66
import com.yapp.core.ui.mvi.MviIntentStore
77
import com.yapp.core.ui.mvi.mviIntentStore
8+
import com.yapp.dataapi.UserRepository
89
import dagger.hilt.android.lifecycle.HiltViewModel
910
import kotlinx.coroutines.flow.catch
1011
import kotlinx.coroutines.flow.launchIn
12+
import kotlinx.coroutines.flow.map
1113
import kotlinx.coroutines.flow.onEach
1214
import javax.inject.Inject
1315

1416
@HiltViewModel
1517
internal class PreviousHistoryViewModel @Inject constructor(
16-
private val previousHistoryUseCase: PreviousHistoryUseCase
18+
private val userRepository: UserRepository
1719
): ViewModel() {
1820

1921
val store: MviIntentStore<PreviousHistoryState, PreviousHistoryIntent, PreviousHistorySideEffect> = mviIntentStore(
@@ -32,13 +34,24 @@ internal class PreviousHistoryViewModel @Inject constructor(
3234
sideEffect(PreviousHistorySideEffect.Finish)
3335
}
3436
PreviousHistoryIntent.OnEntryScreen -> {
35-
previousHistoryUseCase.invoke()
36-
.catch { it.record() }
37-
.onEach { result ->
38-
reduce {
39-
copy(items = result.items)
37+
userRepository.getUserActivityHistories().map { result ->
38+
PreviousHistoryState(
39+
items = result.activityUnits.map { unit ->
40+
PreviousHistoryState.History(
41+
generation = unit.generation,
42+
position = unit.position,
43+
activityStartDate = unit.activityStartDate,
44+
activityEndDate = unit.activityEndDate
45+
)
4046
}
41-
}.launchIn(viewModelScope)
47+
)
48+
}.catch {
49+
it.record()
50+
}.onEach { result ->
51+
reduce {
52+
copy(items = result.items)
53+
}
54+
}.launchIn(viewModelScope)
4255
}
4356
}
4457
}

0 commit comments

Comments
 (0)