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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user