Split v1 creation to create/update
This commit is contained in:
@@ -12,10 +12,7 @@ import gq.kirmanak.mealient.datasource.NetworkError
|
||||
import gq.kirmanak.mealient.datasource.runCatchingExceptCancel
|
||||
import gq.kirmanak.mealient.datasource.v0.MealieDataSourceV0
|
||||
import gq.kirmanak.mealient.datasource.v1.MealieDataSourceV1
|
||||
import gq.kirmanak.mealient.extensions.toFullRecipeInfo
|
||||
import gq.kirmanak.mealient.extensions.toRecipeSummaryInfo
|
||||
import gq.kirmanak.mealient.extensions.toV0Request
|
||||
import gq.kirmanak.mealient.extensions.toV1Request
|
||||
import gq.kirmanak.mealient.extensions.*
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@@ -32,7 +29,10 @@ class MealieDataSourceWrapper @Inject constructor(
|
||||
): String = makeCall { token, url, version ->
|
||||
when (version) {
|
||||
ServerVersion.V0 -> v0Source.addRecipe(url, token, recipe.toV0Request())
|
||||
ServerVersion.V1 -> v1Source.addRecipe(url, token, recipe.toV1Request())
|
||||
ServerVersion.V1 -> {
|
||||
val slug = v1Source.createRecipe(url, token, recipe.toV1CreateRequest())
|
||||
v1Source.updateRecipe(url, token, slug, recipe.toV1UpdateRequest(slug))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ data class FullRecipeInfo(
|
||||
val remoteId: String,
|
||||
val name: String,
|
||||
val slug: String,
|
||||
val image: String,
|
||||
val image: String?,
|
||||
val description: String,
|
||||
val recipeCategories: List<String>,
|
||||
val tags: List<String>,
|
||||
|
||||
@@ -206,7 +206,12 @@ private fun AddRecipeInstructionInfo.toV0Instruction() = AddRecipeInstructionV0(
|
||||
text = text,
|
||||
)
|
||||
|
||||
fun AddRecipeInfo.toV1Request() = AddRecipeRequestV1(
|
||||
|
||||
fun AddRecipeInfo.toV1CreateRequest() = CreateRecipeRequestV1(
|
||||
name = name,
|
||||
)
|
||||
|
||||
fun AddRecipeInfo.toV1UpdateRequest(slug: String) = UpdateRecipeRequestV1(
|
||||
name = name,
|
||||
description = description,
|
||||
image = image,
|
||||
|
||||
Reference in New Issue
Block a user