Fixed recipe add bug

This commit is contained in:
jableader 2024-01-17 19:36:54 +11:00
parent c8b844d3e8
commit 33169c69ef
3 changed files with 6 additions and 6 deletions

View file

@ -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 import units
from products import Product, find_product_by_tag from products import Product, find_product_by_tag

View file

@ -37,7 +37,7 @@ async def create(conn):
async def insert_ingredient(conn, ingredient: Ingredient): async def insert_ingredient(conn, ingredient: Ingredient):
async with conn.execute(''' async with conn.execute('''
INSERT INTO Ingredient (name, line, preparation, unit, quantity, product_id, recipe_id, meal_id) 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.name, ingredient.line, ingredient.preparation, ingredient.unit, ingredient.quantity, ingredient.product_id, ingredient.recipe_id, ingredient.meal_id)) as cursor:
ingredient.id = cursor.lastrowid ingredient.id = cursor.lastrowid

View file

@ -40,9 +40,9 @@ async def parse_ingredients(lines: Annotated[
Query(alias="ingredients", Query(alias="ingredients",
title="Array of ingredients to parse")], title="Array of ingredients to parse")],
conn: sqlite3.Connection = Depends(get_db)) -> List[ingredients.Ingredient]: conn: sqlite3.Connection = Depends(get_db)) -> List[ingredients.Ingredient]:
ingredients = recipes.parse_ingredient_from_nlp(lines) result = ingredients.parse_ingredient_from_nlp(lines)
await recipes.match_existing_products(conn, ingredients) await ingredients.match_existing_products(conn, result)
return ingredients return result
class ProductUrl(BaseModel): class ProductUrl(BaseModel):
url: str url: str
@ -103,7 +103,7 @@ async def create_recipe(item: recipes.Recipe, conn: sqlite3.Connection = Depends
for ingredient in item.ingredients: for ingredient in item.ingredients:
ingredient.recipe_id = item.id ingredient.recipe_id = item.id
ingredient.product_id = ingredient.product.id ingredient.product_id = ingredient.product.id
await recipes.insert_ingredient(conn, ingredient) await ingredients.insert_ingredient(conn, ingredient)
await conn.commit() await conn.commit()
return item return item