diff --git a/ingredients/__init__.py b/ingredients/__init__.py index e7547a2..a88d3df 100644 --- a/ingredients/__init__.py +++ b/ingredients/__init__.py @@ -1,4 +1,4 @@ -from ingredients.db import Ingredient, find_ingredients_by_meal_id, find_ingredients_by_recipe_id +from ingredients.db import Ingredient, find_ingredients_by_meal_id, find_ingredients_by_recipe_id, insert_ingredient import units from products import Product, find_product_by_tag diff --git a/ingredients/db.py b/ingredients/db.py index 8875d5b..1cbf593 100644 --- a/ingredients/db.py +++ b/ingredients/db.py @@ -37,7 +37,7 @@ async def create(conn): async def insert_ingredient(conn, ingredient: Ingredient): async with conn.execute(''' INSERT INTO Ingredient (name, line, preparation, unit, quantity, product_id, recipe_id, meal_id) - VALUES (?, ?, ?, ?, ?, ?, ?) + VALUES (?, ?, ?, ?, ?, ?, ?, ?) ''', (ingredient.name, ingredient.line, ingredient.preparation, ingredient.unit, ingredient.quantity, ingredient.product_id, ingredient.recipe_id, ingredient.meal_id)) as cursor: ingredient.id = cursor.lastrowid diff --git a/main.py b/main.py index e76d1aa..1fbe973 100644 --- a/main.py +++ b/main.py @@ -40,9 +40,9 @@ async def parse_ingredients(lines: Annotated[ Query(alias="ingredients", title="Array of ingredients to parse")], conn: sqlite3.Connection = Depends(get_db)) -> List[ingredients.Ingredient]: - ingredients = recipes.parse_ingredient_from_nlp(lines) - await recipes.match_existing_products(conn, ingredients) - return ingredients + result = ingredients.parse_ingredient_from_nlp(lines) + await ingredients.match_existing_products(conn, result) + return result class ProductUrl(BaseModel): url: str @@ -103,7 +103,7 @@ async def create_recipe(item: recipes.Recipe, conn: sqlite3.Connection = Depends for ingredient in item.ingredients: ingredient.recipe_id = item.id ingredient.product_id = ingredient.product.id - await recipes.insert_ingredient(conn, ingredient) + await ingredients.insert_ingredient(conn, ingredient) await conn.commit() return item