From 6f309d7a890513132f61efad4858a5577e8307d3 Mon Sep 17 00:00:00 2001 From: Miroito <88556823+Miroito@users.noreply.github.com> Date: Tue, 29 Mar 2022 18:07:01 +0200 Subject: [PATCH] feat: keep original text on ingredient parse (#1102) * Keep Original Text on Ingredient Parse * Reorder migration and update test --- ...e9_add_original_text_column_to_recipes_.py | 24 +++++++++++++++++++ .../api/class-interfaces/recipes/types.ts | 1 + .../pages/recipe/_slug/ingredient-parser.vue | 4 +++- frontend/types/api-types/recipe.ts | 1 + mealie/db/models/recipe/ingredient.py | 2 ++ mealie/schema/recipe/recipe_ingredient.py | 1 + .../backup_v2_tests/test_alchemy_exporter.py | 2 +- 7 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 alembic/versions/2022-03-27-19.30.28_f1a2dbee5fe9_add_original_text_column_to_recipes_.py diff --git a/alembic/versions/2022-03-27-19.30.28_f1a2dbee5fe9_add_original_text_column_to_recipes_.py b/alembic/versions/2022-03-27-19.30.28_f1a2dbee5fe9_add_original_text_column_to_recipes_.py new file mode 100644 index 000000000000..62698ded844c --- /dev/null +++ b/alembic/versions/2022-03-27-19.30.28_f1a2dbee5fe9_add_original_text_column_to_recipes_.py @@ -0,0 +1,24 @@ +"""Add original_text column to recipes_ingredients + +Revision ID: f1a2dbee5fe9 +Revises: 263dd6707191 +Create Date: 2022-03-27 19:30:28.545846 + +""" +import sqlalchemy as sa + +from alembic import op + +# revision identifiers, used by Alembic. +revision = "f1a2dbee5fe9" +down_revision = "263dd6707191" +branch_labels = None +depends_on = None + + +def upgrade(): + op.add_column("recipes_ingredients", sa.Column("original_text", sa.String(), nullable=True)) + + +def downgrade(): + op.drop_column("recipes_ingredients", "original_text") diff --git a/frontend/api/class-interfaces/recipes/types.ts b/frontend/api/class-interfaces/recipes/types.ts index 77342e22f834..29d83a227bae 100644 --- a/frontend/api/class-interfaces/recipes/types.ts +++ b/frontend/api/class-interfaces/recipes/types.ts @@ -23,6 +23,7 @@ export interface Ingredient { } export interface ParsedIngredient { + input: string confidence: Confidence; ingredient: Ingredient; } diff --git a/frontend/pages/recipe/_slug/ingredient-parser.vue b/frontend/pages/recipe/_slug/ingredient-parser.vue index 0911533c67ba..4351f979fc6f 100644 --- a/frontend/pages/recipe/_slug/ingredient-parser.vue +++ b/frontend/pages/recipe/_slug/ingredient-parser.vue @@ -88,6 +88,7 @@ import { CreateIngredientFood, CreateIngredientUnit, IngredientFood, IngredientU import RecipeIngredientEditor from "~/components/Domain/Recipe/RecipeIngredientEditor.vue"; import { useUserApi } from "~/composables/api"; import { useFoods, useRecipe, useUnits } from "~/composables/recipes"; +import { RecipeIngredient } from "~/types/api-types/admin"; interface Error { ingredientIndex: number; @@ -218,7 +219,8 @@ export default defineComponent({ let ingredients = parsedIng.value.map((ing) => { return { ...ing.ingredient, - }; + originalText: ing.input + } as RecipeIngredient; }); ingredients = ingredients.map((ing) => { diff --git a/frontend/types/api-types/recipe.ts b/frontend/types/api-types/recipe.ts index 1087e7089f82..824738269663 100644 --- a/frontend/types/api-types/recipe.ts +++ b/frontend/types/api-types/recipe.ts @@ -155,6 +155,7 @@ export interface RecipeIngredient { food?: IngredientFood | CreateIngredientFood; disableAmount?: boolean; quantity?: number; + originalText?: string; referenceId?: string; } export interface Recipe { diff --git a/mealie/db/models/recipe/ingredient.py b/mealie/db/models/recipe/ingredient.py index 56db32b021dd..e0f6c63f56d9 100644 --- a/mealie/db/models/recipe/ingredient.py +++ b/mealie/db/models/recipe/ingredient.py @@ -63,6 +63,8 @@ class RecipeIngredient(SqlAlchemyBase, BaseMixins): food = orm.relationship(IngredientFoodModel, uselist=False) quantity = Column(Float) + original_text = Column(String) + reference_id = Column(GUID) # Reference Links @auto_init() diff --git a/mealie/schema/recipe/recipe_ingredient.py b/mealie/schema/recipe/recipe_ingredient.py index 3ad331e5241c..dbf85b3f6523 100644 --- a/mealie/schema/recipe/recipe_ingredient.py +++ b/mealie/schema/recipe/recipe_ingredient.py @@ -54,6 +54,7 @@ class RecipeIngredient(MealieModel): food: Optional[Union[IngredientFood, CreateIngredientFood]] disable_amount: bool = True quantity: float = 1 + original_text: Optional[str] # Ref is used as a way to distinguish between an individual ingredient on the frontend # It is required for the reorder and section titles to function properly because of how diff --git a/tests/unit_tests/services_tests/backup_v2_tests/test_alchemy_exporter.py b/tests/unit_tests/services_tests/backup_v2_tests/test_alchemy_exporter.py index 3d1e48dc90b9..8b0e5e6f0111 100644 --- a/tests/unit_tests/services_tests/backup_v2_tests/test_alchemy_exporter.py +++ b/tests/unit_tests/services_tests/backup_v2_tests/test_alchemy_exporter.py @@ -4,7 +4,7 @@ from mealie.core.config import get_app_settings from mealie.services.backups_v2.alchemy_exporter import AlchemyExporter ALEMBIC_VERSIONS = [ - {"version_num": "263dd6707191"}, + {"version_num": "f1a2dbee5fe9"}, ]