improve: change db schema for settings
This commit is contained in:
18
api/path.py
18
api/path.py
@@ -55,7 +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())
|
||||
path_created.send(None, payload=new_path.to_dict())
|
||||
return jsonify(new_path.to_dict()), 201
|
||||
|
||||
@path_bp.route('/<int:path_id>', methods=['PUT'])
|
||||
@@ -74,7 +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())
|
||||
path_updated.send(None, payload=path.to_dict())
|
||||
return jsonify(path.to_dict()), 200
|
||||
|
||||
@path_bp.route('/<int:path_id>', methods=['PATCH'])
|
||||
@@ -82,7 +82,7 @@ def update_path(path_id):
|
||||
@require_auth(roles=['admin'])
|
||||
def patch_path(path_id):
|
||||
data = request.json
|
||||
if not data or 'name' not in data and 'parent_id' not in data:
|
||||
if not data:
|
||||
return jsonify({"error": "bad request"}), 400
|
||||
with get_db() as session:
|
||||
path = session.query(Path).get(path_id)
|
||||
@@ -90,13 +90,15 @@ def patch_path(path_id):
|
||||
return jsonify({"error": "path not found"}), 404
|
||||
updated_name =data.get('name', path.name)
|
||||
updated_parent_id = data.get('parent_id', path.parent_id)
|
||||
updated_setting_id = data.get('setting_id', path.setting_id)
|
||||
|
||||
if session.query(Path).filter_by(name=updated_name, parent_id=updated_parent_id).first():
|
||||
if session.query(Path).filter(Path.name==updated_name, Path.parent_id==updated_parent_id, Path.id != path_id).first():
|
||||
return jsonify({"error": "Path already exists under the parent"}), 409
|
||||
path.name = updated_name
|
||||
path.parent_id = updated_parent_id
|
||||
path.setting_id = updated_setting_id
|
||||
session.commit()
|
||||
path_updated.send(None, path.to_dict())
|
||||
path_updated.send(None, payload=path.to_dict())
|
||||
return jsonify(path.to_dict()), 200
|
||||
|
||||
|
||||
@@ -115,7 +117,7 @@ def delete_path(path_id):
|
||||
pth = path.to_dict()
|
||||
session.delete(path)
|
||||
session.commit()
|
||||
path_deleted.send(None, pth)
|
||||
path_deleted.send(None, payload=pth)
|
||||
return jsonify({"message": "path deleted"}), 200
|
||||
|
||||
|
||||
@@ -134,7 +136,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())
|
||||
path_updated.send(None, payload=path.to_dict())
|
||||
return jsonify(path.to_dict()), 200
|
||||
|
||||
|
||||
@@ -154,6 +156,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())
|
||||
path_updated.send(None, payload=path.to_dict())
|
||||
return jsonify(path.to_dict()), 200
|
||||
|
||||
|
||||
Reference in New Issue
Block a user