Skip to content

Commit 0b8ad53

Browse files
committed
fix patch endpoint
1 parent 650863d commit 0b8ad53

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

app/main.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,9 @@ def delete_item(item_id: int):
6161
def update_item(item_id: int, item_body: ItemUpdateSchema):
6262
item_to_update = Item.get_by_id(item_id)
6363

64-
item_to_update.title = item_body.title
65-
item_to_update.price = item_body.price
66-
item_to_update.category = item_body.category
67-
item_to_update.image_url = item_body.image_url
68-
item_to_update.description = item_body.description
64+
for key, value in item_body.dict(exclude_unset=True).items():
65+
setattr(item_to_update, key, value)
66+
6967
item_to_update.save()
7068

7169
return {"operation result": "record updated"}

0 commit comments

Comments
 (0)