API improvements and maybe some "eh" reporting style improvements.
This commit is contained in:
parent
31cc630dcf
commit
cc4bdafa0b
2 changed files with 35 additions and 10 deletions
|
|
@ -6,26 +6,41 @@ def generate_crud_blueprint(model, service):
|
|||
@bp.get('/')
|
||||
def list_items():
|
||||
items = service.list(request.args)
|
||||
return jsonify([item.as_dict() for item in items])
|
||||
try:
|
||||
return jsonify([item.as_dict() for item in items])
|
||||
except Exception as e:
|
||||
return jsonify({"status": "error", "error": str(e)})
|
||||
|
||||
@bp.get('/<int:id>')
|
||||
def get_item(id):
|
||||
item = service.get(id, request.args)
|
||||
return jsonify(item.as_dict())
|
||||
try:
|
||||
return jsonify(item.as_dict())
|
||||
except Exception as e:
|
||||
return jsonify({"status": "error", "error": str(e)})
|
||||
|
||||
@bp.post('/')
|
||||
def create_item():
|
||||
obj = service.create(request.json)
|
||||
return jsonify(obj.as_dict())
|
||||
try:
|
||||
return jsonify(obj.as_dict())
|
||||
except Exception as e:
|
||||
return jsonify({"status": "error", "error": str(e)})
|
||||
|
||||
@bp.patch('/<int:id>')
|
||||
def update_item(id):
|
||||
obj = service.update(id, request.json)
|
||||
return jsonify(obj.as_dict())
|
||||
try:
|
||||
return jsonify(obj.as_dict())
|
||||
except Exception as e:
|
||||
return jsonify({"status": "error", "error": str(e)})
|
||||
|
||||
@bp.delete('/<int:id>')
|
||||
def delete_item(id):
|
||||
service.delete(id)
|
||||
return '', 204
|
||||
try:
|
||||
return jsonify({"status": "success"}), 204
|
||||
except Exception as e:
|
||||
return jsonify({"status": "error", "error": str(e)})
|
||||
|
||||
return bp
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue