TICKET-008 (backend): POST /api/foods/{id}/restore — idempotent, history intact
This commit is contained in:
@@ -12,6 +12,7 @@ from services.foods import (
|
||||
get_food,
|
||||
get_recent_foods,
|
||||
list_foods,
|
||||
restore_food,
|
||||
update_food,
|
||||
)
|
||||
|
||||
@@ -75,6 +76,16 @@ def _update_food(food_id: int, data: FoodUpdate, db: Session = Depends(get_db)):
|
||||
return result
|
||||
|
||||
|
||||
@router.post("/{food_id}/restore", response_model=FoodRead)
|
||||
def _restore_food(food_id: int, db: Session = Depends(get_db)):
|
||||
"""Restore a soft-deleted food: clears deleted_at (spec §3.1).
|
||||
Idempotent — restoring a live food returns it unchanged."""
|
||||
result = restore_food(db, food_id)
|
||||
if result is None:
|
||||
raise HTTPException(status_code=404, detail="Food not found")
|
||||
return result
|
||||
|
||||
|
||||
@router.delete("/{food_id}", response_model=FoodRead)
|
||||
def _delete_food(food_id: int, db: Session = Depends(get_db)):
|
||||
"""Soft-delete: sets deleted_at. Food hidden from search, still visible by id."""
|
||||
|
||||
Reference in New Issue
Block a user