Fixed recipe add bug
This commit is contained in:
parent
c8b844d3e8
commit
33169c69ef
3 changed files with 6 additions and 6 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
8
main.py
8
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue