Skip to content
Snippets Groups Projects
Commit a092d088 authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Add API endpoing to update an item

parent 3e8ac674
No related branches found
No related tags found
No related merge requests found
......@@ -86,6 +86,24 @@ def create_item():
return create_generic_model(Item, mandatory_field='serial_number')
@bp.route('/items/<item_id>', methods=['PATCH'])
@jwt_required
def patch_item(item_id):
data = request.get_json()
if data is None:
raise utils.InventoryError('Body should be a JSON object')
item = Item.query.get(item_id)
if item is None:
raise utils.InventoryError(f'Unknown item id: {item_id}', status_code=422)
item.name = data.get('name', item.name)
item.manufacturer = utils.convert_to_model(data.get('manufacturer', item.manufacturer), Manufacturer)
item.model = utils.convert_to_model(data.get('model', item.model), Model)
item.location = utils.convert_to_model(data.get('location', item.location), Location)
item.status = utils.convert_to_model(data.get('status', item.status), Status)
db.session.commit()
return jsonify(item.to_dict())
@bp.route('/manufacturers')
@jwt_required
def get_manufacturers():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment