feat: add update item name functionality to items route
This commit is contained in:
parent
1c5c5355ee
commit
482396039d
1 changed files with 13 additions and 0 deletions
|
|
@ -83,3 +83,16 @@ def delete_item(item_id: UUID, db: Session = Depends(get_db)):
|
||||||
raise HTTPException(status_code=404, detail="Item not found")
|
raise HTTPException(status_code=404, detail="Item not found")
|
||||||
db.delete(item)
|
db.delete(item)
|
||||||
db.commit()
|
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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue