CachingRecipeRepository

Implementation of the RecipeRepository interface. It uses a local database and a remote API for managing Recipe data.

Constructors

Link copied to clipboard
constructor(recipeDao: RecipeDao, recipeApiService: RecipeApiService)

Functions

Link copied to clipboard
open suspend override fun deleteRecipe(recipe: Recipe)

Deletes a Recipe item from the remote API and the local database.

Link copied to clipboard
open override fun getRecipe(id: Long): Flow<Recipe?>

Fetches a Recipe item by its id from the local database.

Link copied to clipboard
open override fun getRecipes(): Flow<List<Recipe>>

Fetches all Recipe items from the local database. If the local database is empty, it refreshes the data from the remote API.

Link copied to clipboard
open suspend override fun insertRecipe(recipe: Recipe)

Inserts a Recipe item into the local database.

Link copied to clipboard
open suspend override fun refresh()

Refreshes the local database with data fetched from the remote API.

Link copied to clipboard
open suspend override fun saveRecipe(recipe: Recipe): Recipe

Saves a Recipe item to the remote API and the local database. If the item already exists in the remote API, it updates the item. Otherwise, it creates a new item.

Link copied to clipboard
open suspend override fun updateRecipe(recipe: Recipe)

Updates a Recipe item in the remote API and the local database.