feat: Zutaten im Listendialog dem BLS zuordnen
Deploy Development / deploy (push) Successful in 59s
Build Test / pytest-backend (push) Successful in 4s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 23s

Mapping-Status pro Zutat, Suche zuerst Listen und eigene Foods.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-09-13 14:38:42 +02:00
1 parent b37005be01
commit a5adff6196
10 files changed
+237 -23

No files matched your search

+30
View File
@@ -146,6 +146,36 @@ def link_recipes_to_items(cur, profile_id: str) -> tuple[int, list[str]]:
return linked, list(dates)
def list_known_ingredient_names(cur, profile_id: str, limit: int = 2000) -> list[dict[str, Any]]:
"""Distinct list-ingredient names, with mapping if already learned."""
cur.execute(
"""
SELECT i.source_name_raw, i.source_name_normalized,
MIN(m.food_id::text) AS food_id,
MIN(f.name_de) AS food_name_de,
MIN(f.bls_code) AS bls_code,
BOOL_OR(m.id IS NOT NULL) AS mapped
FROM food_recipe_ingredients i
JOIN food_recipes r ON r.id = i.recipe_id
LEFT JOIN food_name_mappings m
ON m.profile_id = r.profile_id
AND m.source_name_normalized = i.source_name_normalized
LEFT JOIN food_catalog f ON f.id = m.food_id
WHERE r.profile_id = %s
GROUP BY i.source_name_raw, i.source_name_normalized
ORDER BY i.source_name_normalized
LIMIT %s
""",
(profile_id, limit),
)
out = []
for row in cur.fetchall():
rec = dict(row)
rec["mapped"] = bool(rec.get("mapped"))
out.append(rec)
return out
def list_recipes(cur, profile_id: str, with_ingredients: bool = True) -> list[dict[str, Any]]:
cur.execute(
"""
+11
View File
@@ -377,6 +377,17 @@ def list_unmapped_foods(
return list_unmapped_payload(get_cursor(conn), pid, since_days, count_only, meta)
@router.get("/ingredient-names")
def list_food_ingredient_names(
x_profile_id: Optional[str] = Header(default=None),
session: dict = Depends(require_auth),
):
from data_layer.food_recipes import list_known_ingredient_names
pid = get_pid(x_profile_id)
with get_db() as conn:
return list_known_ingredient_names(get_cursor(conn), pid)
@router.get("/recipes")
def list_food_recipes(
brief: bool = False,
+21 -1
View File
@@ -1,4 +1,24 @@
from data_layer.food_recipes import save_recipe
from data_layer.food_recipes import list_known_ingredient_names, save_recipe
class _FakeCur:
def __init__(self, rows):
self.rows = rows
def execute(self, sql, params=None):
return None
def fetchall(self):
return self.rows
def test_known_ingredient_names_flags_mapping():
rows = list_known_ingredient_names(_FakeCur([
{"source_name_raw": "Hafer", "source_name_normalized": "hafer", "food_id": "1", "food_name_de": "Haferflocken", "bls_code": "B123", "mapped": True},
{"source_name_raw": "Salz", "source_name_normalized": "salz", "food_id": None, "food_name_de": None, "bls_code": None, "mapped": False},
]), "p")
assert rows[0]["mapped"] is True
assert rows[1]["mapped"] is False
def test_save_recipe_requires_name():
+1 -1
View File
@@ -20,7 +20,7 @@ MODULE_VERSIONS = {
"circumference": "1.0.1",
"caliper": "1.0.1",
"activity": "1.2.1", # Legacy CSV import: activity_entries feature enforcement
"nutrition": "1.3.4", # Listen-Tab; Verknüpfen trotz Mengen-Prefix; Liste wählen ohne Vorfilter
"nutrition": "1.3.5", # Listen-Dialog: Mapping an der Zutat; Suche Listen/eigene vor BLS
"tandoor": "1.0.1", # Router-Import ohne future-annotations (Backend startet)
"bls": "1.0.5", # GET /bls/units
"photos": "1.0.0",