Use AddRecipeRequest mappers
This commit is contained in:
@@ -2,11 +2,7 @@ package gq.kirmanak.mealient.data.add.impl
|
||||
|
||||
import gq.kirmanak.mealient.data.add.AddRecipeDataSource
|
||||
import gq.kirmanak.mealient.data.add.AddRecipeRepo
|
||||
import gq.kirmanak.mealient.data.add.models.AddRecipeIngredient
|
||||
import gq.kirmanak.mealient.data.add.models.AddRecipeInstruction
|
||||
import gq.kirmanak.mealient.data.add.models.AddRecipeRequest
|
||||
import gq.kirmanak.mealient.data.add.models.AddRecipeSettings
|
||||
import gq.kirmanak.mealient.datastore.recipe.AddRecipeDraft
|
||||
import gq.kirmanak.mealient.datastore.recipe.AddRecipeStorage
|
||||
import gq.kirmanak.mealient.logging.Logger
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
@@ -23,32 +19,11 @@ class AddRecipeRepoImpl @Inject constructor(
|
||||
) : AddRecipeRepo {
|
||||
|
||||
override val addRecipeRequestFlow: Flow<AddRecipeRequest>
|
||||
get() = addRecipeStorage.updates.map { it ->
|
||||
AddRecipeRequest(
|
||||
name = it.recipeName,
|
||||
description = it.recipeDescription,
|
||||
recipeYield = it.recipeYield,
|
||||
recipeIngredient = it.recipeIngredients.map { AddRecipeIngredient(note = it) },
|
||||
recipeInstructions = it.recipeInstructions.map { AddRecipeInstruction(text = it) },
|
||||
settings = AddRecipeSettings(
|
||||
public = it.isRecipePublic,
|
||||
disableComments = it.areCommentsDisabled,
|
||||
)
|
||||
)
|
||||
}
|
||||
get() = addRecipeStorage.updates.map { AddRecipeRequest(it) }
|
||||
|
||||
override suspend fun preserve(recipe: AddRecipeRequest) {
|
||||
logger.v { "preserveRecipe() called with: recipe = $recipe" }
|
||||
val input = AddRecipeDraft(
|
||||
recipeName = recipe.name,
|
||||
recipeDescription = recipe.description,
|
||||
recipeYield = recipe.recipeYield,
|
||||
recipeInstructions = recipe.recipeInstructions.map { it.text },
|
||||
recipeIngredients = recipe.recipeIngredient.map { it.note },
|
||||
isRecipePublic = recipe.settings.public,
|
||||
areCommentsDisabled = recipe.settings.disableComments,
|
||||
)
|
||||
addRecipeStorage.save(input)
|
||||
addRecipeStorage.save(recipe.toDraft())
|
||||
}
|
||||
|
||||
override suspend fun clear() {
|
||||
|
||||
Reference in New Issue
Block a user