Complete and total rework ahead.
This commit is contained in:
parent
559fd56f33
commit
e420110fb3
95 changed files with 394 additions and 6351 deletions
0
crudkit/api/__init__.py
Normal file
0
crudkit/api/__init__.py
Normal file
31
crudkit/api/flask_api.py
Normal file
31
crudkit/api/flask_api.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
from flask import Blueprint, jsonify, request
|
||||
|
||||
def generate_crud_blueprint(model, service):
|
||||
bp = Blueprint(model.__name__.lower(), __name__)
|
||||
|
||||
@bp.get('/')
|
||||
def list_items():
|
||||
items = service.list(request.args)
|
||||
return jsonify([item.as_dict() for item in items])
|
||||
|
||||
@bp.get('/<int:id>')
|
||||
def get_item(id):
|
||||
item = service.get(id)
|
||||
return jsonify(item.as_dict())
|
||||
|
||||
@bp.post('/')
|
||||
def create_item():
|
||||
obj = service.create(request.json)
|
||||
return jsonify(obj.as_dict())
|
||||
|
||||
@bp.patch('/<int:id>')
|
||||
def update_item(id):
|
||||
obj = service.update(id, request.json)
|
||||
return jsonify(obj.as_dict())
|
||||
|
||||
@bp.delete('/<int:id>')
|
||||
def delete_item(id):
|
||||
service.delete(id)
|
||||
return '', 204
|
||||
|
||||
return bp
|
||||
Loading…
Add table
Add a link
Reference in a new issue