feat: Eigene Stoffe am Lebensmittel anlegen
EPA-Chips und mg/µg vom Etikett; fehlende Parameter ohne Admin. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
a5adff6196
commit
d35087ad84
9 files changed
+246
-29
No files matched your search
+21
-1
@@ -52,6 +52,12 @@ class SuggestBatchBody(BaseModel):
|
||||
limit: int = 3
|
||||
|
||||
|
||||
class UserAttributeCreate(BaseModel):
|
||||
name_de: str
|
||||
unit: str = "g"
|
||||
attr_key: Optional[str] = None
|
||||
|
||||
|
||||
def _pid(session: dict, x_profile_id: Optional[str] = None) -> str:
|
||||
return x_profile_id or session["profile_id"]
|
||||
|
||||
@@ -100,12 +106,26 @@ def search_foods(
|
||||
@router.get("/attributes")
|
||||
def list_food_attributes(
|
||||
q: str = "",
|
||||
keys: str = "",
|
||||
limit: int = 40,
|
||||
session: dict = Depends(require_auth),
|
||||
):
|
||||
from data_layer.food_attributes import list_numeric_attributes
|
||||
key_list = [p.strip() for p in (keys or "").split(",") if p.strip()]
|
||||
with get_db() as conn:
|
||||
return list_numeric_attributes(get_cursor(conn), q, limit=limit)
|
||||
return list_numeric_attributes(get_cursor(conn), q, limit=limit, keys=key_list or None)
|
||||
|
||||
|
||||
@router.post("/attributes")
|
||||
def create_food_attribute(body: UserAttributeCreate, session: dict = Depends(require_auth)):
|
||||
from data_layer.food_attributes import create_extension_attribute
|
||||
try:
|
||||
with get_db() as conn:
|
||||
return create_extension_attribute(
|
||||
get_cursor(conn), body.name_de, body.unit, body.attr_key
|
||||
)
|
||||
except ValueError as e:
|
||||
raise HTTPException(400, str(e)) from e
|
||||
|
||||
|
||||
@router.post("/foods/suggest-batch")
|
||||
|
||||
Reference in new issue
Block a user