fix: edit function of markdown
This commit is contained in:
22
api/path.py
22
api/path.py
@@ -69,6 +69,28 @@ def update_path(path_id):
|
||||
session.commit()
|
||||
return jsonify(path.to_dict()), 200
|
||||
|
||||
@path_bp.route('/<int:path_id>', methods=['PATCH'])
|
||||
@limiter.limit(api.get_rate_limit)
|
||||
@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:
|
||||
return jsonify({"error": "bad request"}), 400
|
||||
with get_db() as session:
|
||||
path = session.query(Path).get(path_id)
|
||||
if path is None:
|
||||
return jsonify({"error": "path not found"}), 404
|
||||
updated_name =data.get('name', path.name)
|
||||
updated_parent_id = data.get('parent_id', path.parent_id)
|
||||
|
||||
if session.query(Path).filter_by(name=updated_name, parent_id=updated_parent_id).first():
|
||||
return jsonify({"error": "Path already exists under the parent"}), 409
|
||||
path.name = updated_name
|
||||
path.parent_id = updated_parent_id
|
||||
session.commit()
|
||||
return jsonify(path.to_dict()), 200
|
||||
|
||||
|
||||
@path_bp.route('/<int:path_id>', methods=['DELETE'])
|
||||
@limiter.limit(api.get_rate_limit)
|
||||
@require_auth(roles=['admin'])
|
||||
|
||||
Reference in New Issue
Block a user