Remove unused fields

This commit is contained in:
Kirill Kamakin
2022-10-30 12:44:33 +01:00
parent 9ed229f20f
commit 31ccf8822d
12 changed files with 390 additions and 256 deletions

View File

@@ -3,44 +3,21 @@ package gq.kirmanak.mealient.data.add
data class AddRecipeInfo(
val name: String = "",
val description: String = "",
val image: String = "",
val recipeYield: String = "",
val recipeIngredient: List<AddRecipeIngredientInfo> = emptyList(),
val recipeInstructions: List<AddRecipeInstructionInfo> = emptyList(),
val slug: String = "",
val filePath: String = "",
val tags: List<String> = emptyList(),
val categories: List<String> = emptyList(),
val notes: List<AddRecipeNoteInfo> = emptyList(),
val extras: Map<String, String> = emptyMap(),
val assets: List<String> = emptyList(),
val settings: AddRecipeSettingsInfo = AddRecipeSettingsInfo(),
)
data class AddRecipeSettingsInfo(
val disableAmount: Boolean = true,
val disableComments: Boolean = false,
val landscapeView: Boolean = true,
val public: Boolean = true,
val showAssets: Boolean = true,
val showNutrition: Boolean = true,
)
data class AddRecipeNoteInfo(
val title: String = "",
val text: String = "",
)
data class AddRecipeIngredientInfo(
val disableAmount: Boolean = true,
val food: String? = null,
val note: String = "",
val quantity: Int = 1,
val title: String? = null,
val unit: String? = null,
)
data class AddRecipeInstructionInfo(
val title: String = "",
val text: String = "",
)

View File

@@ -1,34 +1,17 @@
package gq.kirmanak.mealient.data.recipes.network
import kotlinx.datetime.LocalDate
import kotlinx.datetime.LocalDateTime
data class FullRecipeInfo(
val remoteId: String,
val name: String,
val slug: String,
val image: String?,
val description: String,
val recipeCategories: List<String>,
val tags: List<String>,
val rating: Int?,
val dateAdded: LocalDate,
val dateUpdated: LocalDateTime,
val recipeYield: String,
val recipeIngredients: List<RecipeIngredientInfo>,
val recipeInstructions: List<RecipeInstructionInfo>,
)
data class RecipeIngredientInfo(
val title: String,
val note: String,
val unit: String,
val food: String,
val disableAmount: Boolean,
val quantity: Double,
)
data class RecipeInstructionInfo(
val title: String,
val text: String,
)

View File

@@ -1,6 +1,9 @@
package gq.kirmanak.mealient.extensions
import gq.kirmanak.mealient.data.add.*
import gq.kirmanak.mealient.data.add.AddRecipeInfo
import gq.kirmanak.mealient.data.add.AddRecipeIngredientInfo
import gq.kirmanak.mealient.data.add.AddRecipeInstructionInfo
import gq.kirmanak.mealient.data.add.AddRecipeSettingsInfo
import gq.kirmanak.mealient.data.baseurl.VersionInfo
import gq.kirmanak.mealient.data.recipes.network.FullRecipeInfo
import gq.kirmanak.mealient.data.recipes.network.RecipeIngredientInfo
@@ -21,17 +24,11 @@ fun FullRecipeInfo.toRecipeEntity() = RecipeEntity(
fun RecipeIngredientInfo.toRecipeIngredientEntity(remoteId: String) = RecipeIngredientEntity(
recipeId = remoteId,
title = title,
note = note,
unit = unit,
food = food,
disableAmount = disableAmount,
quantity = quantity
)
fun RecipeInstructionInfo.toRecipeInstructionEntity(remoteId: String) = RecipeInstructionEntity(
recipeId = remoteId,
title = title,
text = text
)
@@ -104,105 +101,54 @@ fun AddRecipeInfo.toDraft(): AddRecipeDraft = AddRecipeDraft(
fun GetRecipeResponseV0.toFullRecipeInfo() = FullRecipeInfo(
remoteId = remoteId.toString(),
name = name,
slug = slug,
image = image,
description = description,
recipeCategories = recipeCategories,
tags = tags,
rating = rating,
dateAdded = dateAdded,
dateUpdated = dateUpdated,
recipeYield = recipeYield,
recipeIngredients = recipeIngredients.map { it.toRecipeIngredientInfo() },
recipeInstructions = recipeInstructions.map { it.toRecipeInstructionInfo() }
)
fun GetRecipeIngredientResponseV0.toRecipeIngredientInfo() = RecipeIngredientInfo(
title = title,
note = note,
unit = unit,
food = food,
disableAmount = disableAmount,
quantity = quantity
)
fun GetRecipeInstructionResponseV0.toRecipeInstructionInfo() = RecipeInstructionInfo(
title = title,
text = text
)
fun GetRecipeResponseV1.toFullRecipeInfo() = FullRecipeInfo(
remoteId = remoteId,
name = name,
slug = slug,
image = image,
description = description,
recipeCategories = recipeCategories,
tags = tags,
rating = rating,
dateAdded = dateAdded,
dateUpdated = dateUpdated,
recipeYield = recipeYield,
recipeIngredients = recipeIngredients.map { it.toRecipeIngredientInfo() },
recipeInstructions = recipeInstructions.map { it.toRecipeInstructionInfo() }
)
fun GetRecipeIngredientResponseV1.toRecipeIngredientInfo() = RecipeIngredientInfo(
title = title,
note = note,
unit = unit,
food = food,
disableAmount = disableAmount,
quantity = quantity
)
fun GetRecipeInstructionResponseV1.toRecipeInstructionInfo() = RecipeInstructionInfo(
title = title,
text = text
)
fun AddRecipeInfo.toV0Request() = AddRecipeRequestV0(
name = name,
description = description,
image = image,
recipeYield = recipeYield,
recipeIngredient = recipeIngredient.map { it.toV0Ingredient() },
recipeInstructions = recipeInstructions.map { it.toV0Instruction() },
slug = slug,
filePath = filePath,
tags = tags,
categories = categories,
notes = notes.map { it.toV0Note() },
extras = extras,
assets = assets,
settings = settings.toV0Settings(),
)
private fun AddRecipeSettingsInfo.toV0Settings() = AddRecipeSettingsV0(
disableAmount = disableAmount,
disableComments = disableComments,
landscapeView = landscapeView,
public = public,
showAssets = showAssets,
showNutrition = showNutrition,
)
private fun AddRecipeNoteInfo.toV0Note() = AddRecipeNoteV0(
title = title,
text = text,
)
private fun AddRecipeIngredientInfo.toV0Ingredient() = AddRecipeIngredientV0(
disableAmount = disableAmount,
food = food,
note = note,
quantity = quantity,
title = title,
unit = unit
)
private fun AddRecipeInstructionInfo.toV0Instruction() = AddRecipeInstructionV0(
title = title,
text = text,
)
@@ -213,44 +159,22 @@ fun AddRecipeInfo.toV1CreateRequest() = CreateRecipeRequestV1(
fun AddRecipeInfo.toV1UpdateRequest() = UpdateRecipeRequestV1(
description = description,
image = image,
recipeYield = recipeYield,
recipeIngredient = recipeIngredient.map { it.toV1Ingredient() },
recipeInstructions = recipeInstructions.map { it.toV1Instruction() },
filePath = filePath,
tags = tags,
categories = categories,
notes = notes.map { it.toV1Note() },
extras = extras,
assets = assets,
settings = settings.toV1Settings(),
)
private fun AddRecipeSettingsInfo.toV1Settings() = AddRecipeSettingsV1(
disableAmount = disableAmount,
disableComments = disableComments,
landscapeView = landscapeView,
public = public,
showAssets = showAssets,
showNutrition = showNutrition,
)
private fun AddRecipeNoteInfo.toV1Note() = AddRecipeNoteV1(
title = title,
text = text,
)
private fun AddRecipeIngredientInfo.toV1Ingredient() = AddRecipeIngredientV1(
disableAmount = disableAmount,
food = food,
note = note,
quantity = quantity,
title = title,
unit = unit
)
private fun AddRecipeInstructionInfo.toV1Instruction() = AddRecipeInstructionV1(
title = title,
text = text,
ingredientReferences = emptyList(),
)

View File

@@ -64,58 +64,32 @@ object RecipeImplTestData {
)
private val SUGAR_INGREDIENT = RecipeIngredientInfo(
title = "Sugar",
note = "2 oz of white sugar",
unit = "",
food = "",
disableAmount = true,
quantity = 1.0
)
val BREAD_INGREDIENT = RecipeIngredientInfo(
title = "Bread",
note = "2 oz of white bread",
unit = "",
food = "",
disableAmount = false,
quantity = 2.0
)
private val MILK_INGREDIENT = RecipeIngredientInfo(
title = "Milk",
note = "2 oz of white milk",
unit = "",
food = "",
disableAmount = true,
quantity = 3.0
)
val MIX_INSTRUCTION = RecipeInstructionInfo(
title = "Mix",
text = "Mix the ingredients"
)
private val BAKE_INSTRUCTION = RecipeInstructionInfo(
title = "Bake",
text = "Bake the ingredients"
)
private val BOIL_INSTRUCTION = RecipeInstructionInfo(
title = "Boil",
text = "Boil the ingredients"
)
val GET_CAKE_RESPONSE = FullRecipeInfo(
remoteId = "1",
name = "Cake",
slug = "cake",
image = "86",
description = "A tasty cake",
recipeCategories = listOf("dessert", "tasty"),
tags = listOf("gluten", "allergic"),
rating = 4,
dateAdded = LocalDate.parse("2021-11-13"),
dateUpdated = LocalDateTime.parse("2021-11-13T15:30:13"),
recipeYield = "4 servings",
recipeIngredients = listOf(SUGAR_INGREDIENT, BREAD_INGREDIENT),
recipeInstructions = listOf(MIX_INSTRUCTION, BAKE_INSTRUCTION)
@@ -124,14 +98,6 @@ object RecipeImplTestData {
val GET_PORRIDGE_RESPONSE = FullRecipeInfo(
remoteId = "2",
name = "Porridge",
slug = "porridge",
image = "89",
description = "A tasty porridge",
recipeCategories = listOf("porridge", "tasty"),
tags = listOf("gluten", "milk"),
rating = 5,
dateAdded = LocalDate.parse("2021-11-12"),
dateUpdated = LocalDateTime.parse("2021-10-13T17:35:23"),
recipeYield = "3 servings",
recipeIngredients = listOf(SUGAR_INGREDIENT, MILK_INGREDIENT),
recipeInstructions = listOf(MIX_INSTRUCTION, BOIL_INSTRUCTION)
@@ -140,14 +106,12 @@ object RecipeImplTestData {
val MIX_CAKE_RECIPE_INSTRUCTION_ENTITY = RecipeInstructionEntity(
localId = 1,
recipeId = "1",
title = "Mix",
text = "Mix the ingredients",
)
private val BAKE_CAKE_RECIPE_INSTRUCTION_ENTITY = RecipeInstructionEntity(
localId = 2,
recipeId = "1",
title = "Bake",
text = "Bake the ingredients",
)
@@ -159,23 +123,13 @@ object RecipeImplTestData {
private val CAKE_SUGAR_RECIPE_INGREDIENT_ENTITY = RecipeIngredientEntity(
localId = 1,
recipeId = "1",
title = "Sugar",
note = "2 oz of white sugar",
unit = "",
food = "",
disableAmount = true,
quantity = 1.0
)
val CAKE_BREAD_RECIPE_INGREDIENT_ENTITY = RecipeIngredientEntity(
localId = 2,
recipeId = "1",
title = "Bread",
note = "2 oz of white bread",
unit = "",
food = "",
disableAmount = false,
quantity = 2.0
)
val FULL_CAKE_INFO_ENTITY = FullRecipeEntity(
@@ -199,36 +153,24 @@ object RecipeImplTestData {
private val PORRIDGE_MILK_RECIPE_INGREDIENT_ENTITY = RecipeIngredientEntity(
localId = 4,
recipeId = "2",
title = "Milk",
note = "2 oz of white milk",
unit = "",
food = "",
disableAmount = true,
quantity = 3.0
)
private val PORRIDGE_SUGAR_RECIPE_INGREDIENT_ENTITY = RecipeIngredientEntity(
localId = 3,
recipeId = "2",
title = "Sugar",
note = "2 oz of white sugar",
unit = "",
food = "",
disableAmount = true,
quantity = 1.0
)
private val PORRIDGE_MIX_RECIPE_INSTRUCTION_ENTITY = RecipeInstructionEntity(
localId = 3,
recipeId = "2",
title = "Mix",
text = "Mix the ingredients"
)
private val PORRIDGE_BOIL_RECIPE_INSTRUCTION_ENTITY = RecipeInstructionEntity(
localId = 4,
recipeId = "2",
title = "Boil",
text = "Boil the ingredients"
)