-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from lneugebauer/feature/30-add-tags-v2
Add keywords
- Loading branch information
Showing
20 changed files
with
653 additions
and
314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
.../java/de/lukasneugebauer/nextcloudcookbook/recipe/domain/usecase/GetAllKeywordsUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package de.lukasneugebauer.nextcloudcookbook.recipe.domain.usecase | ||
|
||
import com.dropbox.android.external.store4.StoreResponse | ||
import de.lukasneugebauer.nextcloudcookbook.recipe.domain.repository.RecipeRepository | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.mapNotNull | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class GetAllKeywordsUseCase @Inject constructor(private val recipeRepository: RecipeRepository) { | ||
|
||
operator fun invoke(filterByCategory: String? = null): Flow<Set<String>> { | ||
val recipePreviewsFlow = if (filterByCategory.isNullOrBlank()) { | ||
recipeRepository.getRecipePreviews() | ||
} else { | ||
recipeRepository.getRecipePreviewsByCategory(filterByCategory) | ||
} | ||
|
||
return recipePreviewsFlow.mapNotNull { recipePreviewsResponse -> | ||
when (recipePreviewsResponse) { | ||
is StoreResponse.Data -> { | ||
recipePreviewsResponse.value | ||
.flatMap { it.toRecipePreview().keywords } | ||
.toSet() | ||
} | ||
|
||
else -> null | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.