Skip to content

Commit

Permalink
feat(GoalRepository): change getRandomTodoGoal to getTodoGoals
Browse files Browse the repository at this point in the history
  • Loading branch information
murjune committed Jan 30, 2025
1 parent aa1616a commit 0d06f3c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import kotlinx.coroutines.flow.Flow
interface GoalRepository {
fun getSortedGoals(): Flow<List<Goal>>

suspend fun getRandomTodoGoal(): Result<Goal>
suspend fun getTodoGoals(): Result<List<Goal>>

fun getGoal(id: Long): Flow<Goal>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ internal class GoalRepositoryImpl(

override fun getSortedGoals(): Flow<List<Goal>> = goals.map(Goals::sorted)

override suspend fun getRandomTodoGoal(): Result<Goal> {
override suspend fun getTodoGoals(): Result<List<Goal>> {
return runCatching {
val goals: Goals =
goals.firstOrNull() ?: error("if Goals empty, cannot get random todo goal")
val todoGoals: List<Goal> = goals.getTodoGoals()
todoGoals.random()
goals.getTodoGoals()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,7 @@ internal class DashboardViewModel(
)

init {
viewModelScope.launch {
goalRepository.getRandomTodoGoal()
.onSuccess { goal ->
bubbleTitle.value = goal.title
}
.onFailure {
// TODO : Error 처리
Log.e("DashboardViewModel", "Fail to get random todo goal", it)
}
}
changeBubble()
}

fun setGoalNotificationEnabled(enabled: Boolean) {
Expand Down Expand Up @@ -118,9 +109,11 @@ internal class DashboardViewModel(

fun changeBubble() {
viewModelScope.launch {
goalRepository.getRandomTodoGoal()
.onSuccess { goal ->
bubbleTitle.value = goal.title
goalRepository.getTodoGoals()
.onSuccess { goals ->
if (goals.isNotEmpty()) {
bubbleTitle.value = goals.random().title
}
}
.onFailure {
// TODO : Error 처리
Expand Down

0 comments on commit 0d06f3c

Please sign in to comment.