fix: edit function of markdown
This commit is contained in:
@@ -67,7 +67,7 @@ def create_markdown():
|
||||
session.rollback()
|
||||
return jsonify({"error": f"create failed - {errno}"}), 500
|
||||
|
||||
@markdown_bp.route('/<int:markdown_id>', methods=['PUT'])
|
||||
@markdown_bp.route('/<int:markdown_id>', methods=['PUT', 'PATCH'])
|
||||
@require_auth(roles=['admin', 'creator'])
|
||||
@limiter.limit(api.get_rate_limit)
|
||||
def update_markdown(markdown_id):
|
||||
@@ -76,9 +76,17 @@ def update_markdown(markdown_id):
|
||||
if markdown is None:
|
||||
return jsonify({"error": "file not found"}), 404
|
||||
data = request.json
|
||||
markdown.title = data.get('title')
|
||||
markdown.content = data.get('content')
|
||||
markdown.path_id = data.get('path_id')
|
||||
if request.method == "PUT":
|
||||
markdown.title = data.get('title')
|
||||
markdown.content = data.get('content')
|
||||
markdown.path_id = data.get('path_id')
|
||||
elif request.method == "PATCH":
|
||||
if 'title' in data:
|
||||
markdown.title = data.get('title')
|
||||
if 'content' in data:
|
||||
markdown.content = data.get('content')
|
||||
if 'path_id' in data:
|
||||
markdown.path_id = data.get('path_id')
|
||||
session.commit()
|
||||
return jsonify(markdown.to_dict()), 200
|
||||
|
||||
|
||||
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