diff --git a/app/src/main/java/gq/kirmanak/mealient/data/impl/util/RemoteToLocalMappings.kt b/app/src/main/java/gq/kirmanak/mealient/data/impl/util/RemoteToLocalMappings.kt new file mode 100644 index 0000000..fb8a4be --- /dev/null +++ b/app/src/main/java/gq/kirmanak/mealient/data/impl/util/RemoteToLocalMappings.kt @@ -0,0 +1,44 @@ +package gq.kirmanak.mealient.data.impl.util + +import gq.kirmanak.mealient.data.recipes.db.entity.RecipeEntity +import gq.kirmanak.mealient.data.recipes.db.entity.RecipeIngredientEntity +import gq.kirmanak.mealient.data.recipes.db.entity.RecipeInstructionEntity +import gq.kirmanak.mealient.data.recipes.db.entity.RecipeSummaryEntity +import gq.kirmanak.mealient.data.recipes.network.response.GetRecipeIngredientResponse +import gq.kirmanak.mealient.data.recipes.network.response.GetRecipeInstructionResponse +import gq.kirmanak.mealient.data.recipes.network.response.GetRecipeResponse +import gq.kirmanak.mealient.data.recipes.network.response.GetRecipeSummaryResponse + +fun GetRecipeResponse.toRecipeEntity() = RecipeEntity( + remoteId = remoteId, + recipeYield = recipeYield +) + +fun GetRecipeIngredientResponse.toRecipeIngredientEntity(remoteId: Long) = + RecipeIngredientEntity( + recipeId = remoteId, + title = title, + note = note, + unit = unit, + food = food, + disableAmount = disableAmount, + quantity = quantity + ) + +fun GetRecipeInstructionResponse.toRecipeInstructionEntity(remoteId: Long) = + RecipeInstructionEntity( + recipeId = remoteId, + title = title, + text = text + ) + +fun GetRecipeSummaryResponse.recipeEntity() = RecipeSummaryEntity( + remoteId = remoteId, + name = name, + slug = slug, + image = image, + description = description, + rating = rating, + dateAdded = dateAdded, + dateUpdated = dateUpdated, +) diff --git a/app/src/main/java/gq/kirmanak/mealient/data/recipes/db/RecipeStorageImpl.kt b/app/src/main/java/gq/kirmanak/mealient/data/recipes/db/RecipeStorageImpl.kt index 5fe7305..2a55d28 100644 --- a/app/src/main/java/gq/kirmanak/mealient/data/recipes/db/RecipeStorageImpl.kt +++ b/app/src/main/java/gq/kirmanak/mealient/data/recipes/db/RecipeStorageImpl.kt @@ -3,10 +3,12 @@ package gq.kirmanak.mealient.data.recipes.db import androidx.paging.PagingSource import androidx.room.withTransaction import gq.kirmanak.mealient.data.AppDb +import gq.kirmanak.mealient.data.impl.util.recipeEntity +import gq.kirmanak.mealient.data.impl.util.toRecipeEntity +import gq.kirmanak.mealient.data.impl.util.toRecipeIngredientEntity +import gq.kirmanak.mealient.data.impl.util.toRecipeInstructionEntity import gq.kirmanak.mealient.data.recipes.db.entity.* import gq.kirmanak.mealient.data.recipes.impl.FullRecipeInfo -import gq.kirmanak.mealient.data.recipes.network.response.GetRecipeIngredientResponse -import gq.kirmanak.mealient.data.recipes.network.response.GetRecipeInstructionResponse import gq.kirmanak.mealient.data.recipes.network.response.GetRecipeResponse import gq.kirmanak.mealient.data.recipes.network.response.GetRecipeSummaryResponse import timber.log.Timber @@ -85,16 +87,6 @@ class RecipeStorageImpl @Inject constructor( return tagId } - private fun GetRecipeSummaryResponse.recipeEntity() = RecipeSummaryEntity( - remoteId = remoteId, - name = name, - slug = slug, - image = image, - description = description, - rating = rating, - dateAdded = dateAdded, - dateUpdated = dateUpdated, - ) override fun queryRecipes(): PagingSource { Timber.v("queryRecipes() called") @@ -137,29 +129,6 @@ class RecipeStorageImpl @Inject constructor( } } - private fun GetRecipeResponse.toRecipeEntity() = RecipeEntity( - remoteId = remoteId, - recipeYield = recipeYield - ) - - private fun GetRecipeIngredientResponse.toRecipeIngredientEntity(remoteId: Long) = - RecipeIngredientEntity( - recipeId = remoteId, - title = title, - note = note, - unit = unit, - food = food, - disableAmount = disableAmount, - quantity = quantity - ) - - private fun GetRecipeInstructionResponse.toRecipeInstructionEntity(remoteId: Long) = - RecipeInstructionEntity( - recipeId = remoteId, - title = title, - text = text - ) - override suspend fun queryRecipeInfo(recipeId: Long): FullRecipeInfo { Timber.v("queryRecipeInfo() called with: recipeId = $recipeId") val fullRecipeInfo = checkNotNull(recipeDao.queryFullRecipeInfo(recipeId)) {