summaryrefslogtreecommitdiff
path: root/routers/grocery.py
diff options
context:
space:
mode:
authorTyler Hoang <tyler@tylerhoang.xyz>2026-05-09 01:19:08 -0700
committerTyler Hoang <tyler@tylerhoang.xyz>2026-05-09 01:19:08 -0700
commit75ce40635736260ce5a19b7a33856305ee516ccc (patch)
tree9db3931eae3dbd9308bab0e240e7c75950bcbd4c /routers/grocery.py
parent3de7c5eed5ba262abf0d746211e33800db6d66df (diff)
Simplify pantry UX and persist grocery check state server-side
- Remove quantity, unit, expiry, and category fields from pantry form; auto-detect category via keyword map - Persist grocery item checked/unchecked state in DB via PATCH /api/grocery/{id}/check-item - Fix unchecking: previously bailed early and never removed the checked class - Fix NOT NULL constraint on ingredients.unit by defaulting to empty string Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'routers/grocery.py')
-rw-r--r--routers/grocery.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/routers/grocery.py b/routers/grocery.py
index 17215d2..cbc66bb 100644
--- a/routers/grocery.py
+++ b/routers/grocery.py
@@ -130,6 +130,43 @@ async def delete_current_grocery_list(db: Session = Depends(get_db)):
return {"status": "deleted"}
+@router.patch("/{id}/check-item")
+async def check_grocery_item(id: int, request: dict = Body(...), db: Session = Depends(get_db)):
+ """Mark a grocery item as checked/unchecked."""
+ grocery_list = db.query(GroceryList).filter(GroceryList.id == id).first()
+ if not grocery_list:
+ raise HTTPException(status_code=404, detail="Grocery list not found")
+
+ item_name = request.get("name")
+ checked = request.get("checked", False)
+
+ if not item_name:
+ raise HTTPException(status_code=400, detail="Item name is required")
+
+ # Parse items
+ try:
+ items = json.loads(grocery_list.items)
+ except json.JSONDecodeError:
+ items = []
+
+ # Find and update the item
+ item_found = False
+ for item in items:
+ if isinstance(item, dict) and item.get("name") == item_name:
+ item["checked"] = checked
+ item_found = True
+ break
+
+ if not item_found:
+ raise HTTPException(status_code=404, detail="Item not found in grocery list")
+
+ # Save back to database
+ grocery_list.items = json.dumps(items)
+ db.commit()
+
+ return {"status": "ok"}
+
+
@router.put("/{id}/purchased")
async def mark_purchased(id: int, db: Session = Depends(get_db)):
"""Mark a grocery list as purchased and update pantry."""