27 lines
866 B
Python
27 lines
866 B
Python
|
|
from __future__ import annotations
|
||
|
|
from typing import List
|
||
|
|
|
||
|
|
from fastapi import APIRouter, Depends, Query
|
||
|
|
import aiosqlite
|
||
|
|
|
||
|
|
import ingredients as ingredients_mod
|
||
|
|
from api.deps import get_db, get_household_from_slug
|
||
|
|
|
||
|
|
|
||
|
|
router = APIRouter(prefix="/households/{householdSlug}/ingredients", tags=["ingredients"])
|
||
|
|
|
||
|
|
|
||
|
|
@router.get("/parse", response_model=list[ingredients_mod.Ingredient], summary="Parse an ingredient line from a string")
|
||
|
|
async def parse_ingredient(
|
||
|
|
lines: List[str] = Query(..., description="Multiple ingredient lines to parse"),
|
||
|
|
household=Depends(get_household_from_slug),
|
||
|
|
conn: aiosqlite.Connection = Depends(get_db),
|
||
|
|
):
|
||
|
|
# NLP parse + best-effort product match
|
||
|
|
parsed = [ingredients_mod.parse_ingredient_from_nlp(line) for line in lines]
|
||
|
|
matched = await ingredients_mod.match_existing_products(conn, parsed)
|
||
|
|
|
||
|
|
return matched
|
||
|
|
|
||
|
|
|