add: webhook
This commit is contained in:
10
api/path.py
10
api/path.py
@@ -7,6 +7,9 @@ from db.models.Markdown import Markdown
|
||||
from db.models.Path import Path
|
||||
from api import limiter
|
||||
import logging
|
||||
|
||||
from events import path_created, path_updated, path_deleted
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
path_bp = Blueprint('path', __name__, url_prefix='/api/path')
|
||||
@@ -52,6 +55,7 @@ def create_path():
|
||||
new_path = Path(name=data['name'], parent_id=data['parent_id'])
|
||||
session.add(new_path)
|
||||
session.commit()
|
||||
path_created.send(None, new_path.to_dict())
|
||||
return jsonify(new_path.to_dict()), 201
|
||||
|
||||
@path_bp.route('/<int:path_id>', methods=['PUT'])
|
||||
@@ -70,6 +74,7 @@ def update_path(path_id):
|
||||
path.name = data['name']
|
||||
path.parent_id = data['parent_id']
|
||||
session.commit()
|
||||
path_updated.send(None, path.to_dict())
|
||||
return jsonify(path.to_dict()), 200
|
||||
|
||||
@path_bp.route('/<int:path_id>', methods=['PATCH'])
|
||||
@@ -91,6 +96,7 @@ def patch_path(path_id):
|
||||
path.name = updated_name
|
||||
path.parent_id = updated_parent_id
|
||||
session.commit()
|
||||
path_updated.send(None, path.to_dict())
|
||||
return jsonify(path.to_dict()), 200
|
||||
|
||||
|
||||
@@ -106,8 +112,10 @@ def delete_path(path_id):
|
||||
return jsonify({"error": "can not delete non empty path"}), 409
|
||||
if session.query(Markdown).filter_by(path_id=path_id).first():
|
||||
return jsonify({"error": "can not delete non empty path"}), 409
|
||||
pth = path.to_dict()
|
||||
session.delete(path)
|
||||
session.commit()
|
||||
path_deleted.send(None, pth)
|
||||
return jsonify({"message": "path deleted"}), 200
|
||||
|
||||
|
||||
@@ -126,6 +134,7 @@ def move_forward(path_id):
|
||||
previous_path = siblings[current_index - 1]
|
||||
path.order, previous_path.order = previous_path.order, path.order
|
||||
session.commit()
|
||||
path_updated.send(None, path.to_dict())
|
||||
return jsonify(path.to_dict()), 200
|
||||
|
||||
|
||||
@@ -145,5 +154,6 @@ def move_backward(path_id):
|
||||
next_path = siblings[current_index + 1]
|
||||
path.order, next_path.order = next_path.order, path.order
|
||||
session.commit()
|
||||
path_updated.send(None, path.to_dict())
|
||||
return jsonify(path.to_dict()), 200
|
||||
|
||||
|
||||
Reference in New Issue
Block a user