feat: add update item name functionality to items route

This commit is contained in:
Felix Zett 2025-08-31 19:44:53 +02:00
parent 1c5c5355ee
commit 482396039d

View file

@ -83,3 +83,16 @@ def delete_item(item_id: UUID, db: Session = Depends(get_db)):
raise HTTPException(status_code=404, detail="Item not found")
db.delete(item)
db.commit()
@router.put("/{item_id}", response_model=ItemOut)
def update_item_name(item_id: UUID, payload: dict, db: Session = Depends(get_db)):
item = db.get(models.Item, item_id)
if not item:
raise HTTPException(status_code=404, detail="Item not found")
name = payload.get("name")
if not name or not isinstance(name, str):
raise HTTPException(status_code=400, detail="Missing or invalid name")
item.name = name
db.commit()
db.refresh(item)
return item