Coverage Summary for Class: GetCategoriesUseCase (com.georgeci.moneysurfer.domain.usecase)
| Class |
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
| GetCategoriesUseCase |
100%
(3/3)
|
66.7%
(4/6)
|
100%
(5/5)
|
100%
(14/14)
|
| GetCategoriesUseCase$invoke$$inlined$flatMapLatest$1 |
0%
(0/1)
|
|
| Total |
75%
(3/4)
|
66.7%
(4/6)
|
100%
(5/5)
|
100%
(14/14)
|
package com.georgeci.moneysurfer.domain.usecase
import com.georgeci.moneysurfer.domain.auth.SessionPointers
import com.georgeci.moneysurfer.domain.model.Category
import com.georgeci.moneysurfer.domain.repositories.CategoryRepository
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
import org.koin.core.annotation.Single
@Single
@OptIn(ExperimentalCoroutinesApi::class)
class GetCategoriesUseCase(
private val categoryRepository: CategoryRepository,
private val session: SessionPointers,
) {
operator fun invoke(): Flow<List<Category>> =
session.currentWorkspaceId.flatMapLatest { workspaceId ->
workspaceId?.let(categoryRepository::getByWorkspaceId) ?: flowOf(emptyList())
}
}