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
@@ -487,3 +487,45 @@ def dates_for_normalized_name(cur, profile_id: str, source_name_normalized: str)
|
||||
(profile_id, source_name_normalized, profile_id, source_name_normalized),
|
||||
)
|
||||
return [r["date"] for r in cur.fetchall()]
|
||||
|
||||
|
||||
def dates_using_food(cur, profile_id: str, food_id: str) -> list[str]:
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT DISTINCT date::text AS date
|
||||
FROM nutrition_items
|
||||
WHERE profile_id = %s AND food_id = %s
|
||||
UNION
|
||||
SELECT DISTINCT i.date::text AS date
|
||||
FROM nutrition_items i
|
||||
JOIN food_recipe_ingredients ri ON ri.recipe_id = i.recipe_id
|
||||
JOIN food_name_mappings m
|
||||
ON m.profile_id = i.profile_id
|
||||
AND m.source_name_normalized = ri.source_name_normalized
|
||||
AND m.food_id = %s
|
||||
WHERE i.profile_id = %s AND i.recipe_id IS NOT NULL
|
||||
""",
|
||||
(profile_id, food_id, food_id, profile_id),
|
||||
)
|
||||
return [r["date"] for r in cur.fetchall() if r.get("date")]
|
||||
|
||||
|
||||
def profiles_dates_using_food(cur, food_id: str) -> list[tuple[str, str]]:
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT DISTINCT profile_id::text AS profile_id, date::text AS date
|
||||
FROM nutrition_items
|
||||
WHERE food_id = %s
|
||||
UNION
|
||||
SELECT DISTINCT i.profile_id::text AS profile_id, i.date::text AS date
|
||||
FROM nutrition_items i
|
||||
JOIN food_recipe_ingredients ri ON ri.recipe_id = i.recipe_id
|
||||
JOIN food_name_mappings m
|
||||
ON m.profile_id = i.profile_id
|
||||
AND m.source_name_normalized = ri.source_name_normalized
|
||||
AND m.food_id = %s
|
||||
WHERE i.recipe_id IS NOT NULL
|
||||
""",
|
||||
(food_id, food_id),
|
||||
)
|
||||
return [(r["profile_id"], r["date"]) for r in cur.fetchall() if r.get("profile_id") and r.get("date")]
|
||||
Reference in new issue
Block a user