feat: drag-and-drop meal scheduling + 7-day grid

This commit is contained in:
2026-05-14 15:49:43 -07:00
parent c21741dd56
commit 301e984336
5 changed files with 310 additions and 47 deletions
+42 -1
View File
@@ -319,4 +319,45 @@ def swap_meal_item(item_id: UUID, new_recipe_id: UUID, db: Session = Depends(get
item.denial_details = None
db.commit()
return {"message": "Meal swapped", "item": item}
return {"message": "Meal swapped", "item": item}
@router.put("/items/{item_id}/move")
def move_meal_item(
item_id: UUID,
new_day_of_week: int,
new_meal_type: str,
db: Session = Depends(get_db),
):
"""Move a meal to a new day/type slot.
If the target slot is occupied by another item in the same meal plan,
swap the two items.
"""
item = db.query(MealPlanItem).filter(MealPlanItem.id == item_id).first()
if not item:
raise HTTPException(status_code=404, detail="Meal plan item not found")
plan_id = item.meal_plan_id
conflict = (
db.query(MealPlanItem)
.filter(
MealPlanItem.meal_plan_id == plan_id,
MealPlanItem.day_of_week == new_day_of_week,
MealPlanItem.meal_type == new_meal_type,
MealPlanItem.id != item_id,
)
.first()
)
if conflict:
# swap day/type
conflict.day_of_week = item.day_of_week
conflict.meal_type = item.meal_type
item.day_of_week = new_day_of_week
item.meal_type = new_meal_type
db.commit()
db.refresh(item)
return {"message": "Meal moved", "item": item}