feat: Eigene und zentrale Lebensmittel bearbeiten, mit Sichtbarkeit im Mapping
Nutzer können persönliche Foods anlegen und ändern; der Admin legt zentrale Einträge für alle an. Suche und Namens-Mapping berücksichtigen persönlich, zentral und BLS. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
d35087ad84
commit
8b1e1da5d8
30 files changed
+1195
-120
No files matched your search
@@ -52,7 +52,8 @@ def list_food_mappings(
|
||||
q += " WHERE " + " AND ".join(conds)
|
||||
q += " ORDER BY m.source_name_normalized"
|
||||
cur.execute(q, params)
|
||||
return [r2d(r) for r in cur.fetchall()]
|
||||
from data_layer.food_visibility import attach_visibility
|
||||
return [attach_visibility(r2d(r)) for r in cur.fetchall()]
|
||||
|
||||
|
||||
@router.get("/stats/coverage")
|
||||
@@ -77,9 +78,13 @@ def mapping_coverage(session: dict = Depends(require_admin)):
|
||||
def create_food_mapping(body: FoodMappingCreate, session: dict = Depends(require_admin)):
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
cur.execute("SELECT id FROM food_catalog WHERE id = %s", (body.food_id,))
|
||||
if not cur.fetchone():
|
||||
raise HTTPException(404, "Lebensmittel nicht gefunden")
|
||||
from data_layer.food_visibility import require_mapping_target
|
||||
try:
|
||||
require_mapping_target(cur, body.food_id, body.profile_id or None)
|
||||
except LookupError as e:
|
||||
raise HTTPException(404, str(e)) from e
|
||||
except PermissionError as e:
|
||||
raise HTTPException(400, str(e)) from e
|
||||
mid = upsert_food_mapping(
|
||||
cur,
|
||||
source_name_raw=body.source_name,
|
||||
@@ -114,9 +119,17 @@ def update_food_mapping(mapping_id: int, body: FoodMappingUpdate, session: dict
|
||||
row = cur.fetchone()
|
||||
if not row:
|
||||
raise HTTPException(404, "Mapping nicht gefunden")
|
||||
cur.execute("SELECT id FROM food_catalog WHERE id = %s AND is_active = true", (body.food_id,))
|
||||
if not cur.fetchone():
|
||||
cur.execute("SELECT id, catalog_kind, owner_profile_id, is_active FROM food_catalog WHERE id = %s AND is_active = true", (body.food_id,))
|
||||
food = cur.fetchone()
|
||||
if not food:
|
||||
raise HTTPException(404, "Lebensmittel nicht gefunden")
|
||||
from data_layer.food_visibility import require_mapping_target
|
||||
try:
|
||||
require_mapping_target(cur, body.food_id, row.get("profile_id"))
|
||||
except LookupError as e:
|
||||
raise HTTPException(404, str(e)) from e
|
||||
except PermissionError as e:
|
||||
raise HTTPException(400, str(e)) from e
|
||||
cur.execute(
|
||||
"""
|
||||
UPDATE food_name_mappings
|
||||
|
||||
Reference in new issue
Block a user