Fix parsing update recipe response
This commit is contained in:
@@ -31,7 +31,8 @@ class MealieDataSourceWrapper @Inject constructor(
|
|||||||
ServerVersion.V0 -> v0Source.addRecipe(url, token, recipe.toV0Request())
|
ServerVersion.V0 -> v0Source.addRecipe(url, token, recipe.toV0Request())
|
||||||
ServerVersion.V1 -> {
|
ServerVersion.V1 -> {
|
||||||
val slug = v1Source.createRecipe(url, token, recipe.toV1CreateRequest())
|
val slug = v1Source.createRecipe(url, token, recipe.toV1CreateRequest())
|
||||||
v1Source.updateRecipe(url, token, slug, recipe.toV1UpdateRequest(slug))
|
v1Source.updateRecipe(url, token, slug, recipe.toV1UpdateRequest())
|
||||||
|
slug
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -211,14 +211,12 @@ fun AddRecipeInfo.toV1CreateRequest() = CreateRecipeRequestV1(
|
|||||||
name = name,
|
name = name,
|
||||||
)
|
)
|
||||||
|
|
||||||
fun AddRecipeInfo.toV1UpdateRequest(slug: String) = UpdateRecipeRequestV1(
|
fun AddRecipeInfo.toV1UpdateRequest() = UpdateRecipeRequestV1(
|
||||||
name = name,
|
|
||||||
description = description,
|
description = description,
|
||||||
image = image,
|
image = image,
|
||||||
recipeYield = recipeYield,
|
recipeYield = recipeYield,
|
||||||
recipeIngredient = recipeIngredient.map { it.toV1Ingredient() },
|
recipeIngredient = recipeIngredient.map { it.toV1Ingredient() },
|
||||||
recipeInstructions = recipeInstructions.map { it.toV1Instruction() },
|
recipeInstructions = recipeInstructions.map { it.toV1Instruction() },
|
||||||
slug = slug,
|
|
||||||
filePath = filePath,
|
filePath = filePath,
|
||||||
tags = tags,
|
tags = tags,
|
||||||
categories = categories,
|
categories = categories,
|
||||||
@@ -254,4 +252,5 @@ private fun AddRecipeIngredientInfo.toV1Ingredient() = AddRecipeIngredientV1(
|
|||||||
private fun AddRecipeInstructionInfo.toV1Instruction() = AddRecipeInstructionV1(
|
private fun AddRecipeInstructionInfo.toV1Instruction() = AddRecipeInstructionV1(
|
||||||
title = title,
|
title = title,
|
||||||
text = text,
|
text = text,
|
||||||
|
ingredientReferences = emptyList(),
|
||||||
)
|
)
|
||||||
@@ -15,7 +15,7 @@ interface MealieDataSourceV1 {
|
|||||||
token: String?,
|
token: String?,
|
||||||
slug: String,
|
slug: String,
|
||||||
recipe: UpdateRecipeRequestV1,
|
recipe: UpdateRecipeRequestV1,
|
||||||
): String
|
): GetRecipeResponseV1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to acquire authentication token using the provided credentials
|
* Tries to acquire authentication token using the provided credentials
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class MealieDataSourceV1Impl @Inject constructor(
|
|||||||
token: String?,
|
token: String?,
|
||||||
slug: String,
|
slug: String,
|
||||||
recipe: UpdateRecipeRequestV1
|
recipe: UpdateRecipeRequestV1
|
||||||
): String = networkRequestWrapper.makeCallAndHandleUnauthorized(
|
): GetRecipeResponseV1 = networkRequestWrapper.makeCallAndHandleUnauthorized(
|
||||||
block = { service.updateRecipe("$baseUrl/api/recipes/$slug", token, recipe) },
|
block = { service.updateRecipe("$baseUrl/api/recipes/$slug", token, recipe) },
|
||||||
logMethod = { "updateRecipe" },
|
logMethod = { "updateRecipe" },
|
||||||
logParameters = { "baseUrl = $baseUrl, token = $token, slug = $slug, recipe = $recipe" }
|
logParameters = { "baseUrl = $baseUrl, token = $token, slug = $slug, recipe = $recipe" }
|
||||||
|
|||||||
@@ -21,12 +21,12 @@ interface MealieServiceV1 {
|
|||||||
@Body addRecipeRequest: CreateRecipeRequestV1,
|
@Body addRecipeRequest: CreateRecipeRequestV1,
|
||||||
): String
|
): String
|
||||||
|
|
||||||
@PUT
|
@PATCH
|
||||||
suspend fun updateRecipe(
|
suspend fun updateRecipe(
|
||||||
@Url url: String,
|
@Url url: String,
|
||||||
@Header(AUTHORIZATION_HEADER_NAME) token: String?,
|
@Header(AUTHORIZATION_HEADER_NAME) token: String?,
|
||||||
@Body addRecipeRequest: UpdateRecipeRequestV1,
|
@Body addRecipeRequest: UpdateRecipeRequestV1,
|
||||||
): String
|
): GetRecipeResponseV1
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
suspend fun getVersion(
|
suspend fun getVersion(
|
||||||
|
|||||||
@@ -5,13 +5,11 @@ import kotlinx.serialization.Serializable
|
|||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class UpdateRecipeRequestV1(
|
data class UpdateRecipeRequestV1(
|
||||||
@SerialName("name") val name: String = "",
|
|
||||||
@SerialName("description") val description: String = "",
|
@SerialName("description") val description: String = "",
|
||||||
@SerialName("image") val image: String = "",
|
@SerialName("image") val image: String = "",
|
||||||
@SerialName("recipeYield") val recipeYield: String = "",
|
@SerialName("recipeYield") val recipeYield: String = "",
|
||||||
@SerialName("recipeIngredient") val recipeIngredient: List<AddRecipeIngredientV1> = emptyList(),
|
@SerialName("recipeIngredient") val recipeIngredient: List<AddRecipeIngredientV1> = emptyList(),
|
||||||
@SerialName("recipeInstructions") val recipeInstructions: List<AddRecipeInstructionV1> = emptyList(),
|
@SerialName("recipeInstructions") val recipeInstructions: List<AddRecipeInstructionV1> = emptyList(),
|
||||||
@SerialName("slug") val slug: String = "",
|
|
||||||
@SerialName("filePath") val filePath: String = "",
|
@SerialName("filePath") val filePath: String = "",
|
||||||
@SerialName("tags") val tags: List<String> = emptyList(),
|
@SerialName("tags") val tags: List<String> = emptyList(),
|
||||||
@SerialName("categories") val categories: List<String> = emptyList(),
|
@SerialName("categories") val categories: List<String> = emptyList(),
|
||||||
@@ -35,6 +33,7 @@ data class AddRecipeIngredientV1(
|
|||||||
data class AddRecipeInstructionV1(
|
data class AddRecipeInstructionV1(
|
||||||
@SerialName("title") val title: String = "",
|
@SerialName("title") val title: String = "",
|
||||||
@SerialName("text") val text: String = "",
|
@SerialName("text") val text: String = "",
|
||||||
|
@SerialName("ingredientReferences") val ingredientReferences: List<String> = emptyList(),
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
|||||||
Reference in New Issue
Block a user