add: order paths & mds
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from flask import Blueprint, request, jsonify
|
||||
|
||||
import api
|
||||
from api import require_auth, etag_response
|
||||
from contexts.RequestContext import RequestContext
|
||||
@@ -113,4 +114,42 @@ def delete_markdown(markdown_id):
|
||||
return jsonify({"error": f"file not found - {errno}"}), 404
|
||||
session.delete(markdown)
|
||||
session.commit()
|
||||
return jsonify({"message": "deleted"}), 200
|
||||
return jsonify({"message": "deleted"}), 200
|
||||
|
||||
|
||||
@markdown_bp.route('/move_forward/<int:markdown_id>', methods=['PATCH'])
|
||||
@require_auth(roles=['admin'])
|
||||
@limiter.limit(api.get_rate_limit)
|
||||
def move_forward(markdown_id):
|
||||
with get_db() as session:
|
||||
markdown = session.query(Markdown).get(markdown_id)
|
||||
if not markdown:
|
||||
return jsonify({"error": "file not found"}), 404
|
||||
siblings = session.query(Markdown).filter(Markdown.path_id == markdown.path_id).order_by(Markdown.order).all()
|
||||
current_index = siblings.index(markdown)
|
||||
if current_index == 0:
|
||||
return jsonify({"error": "already at the first position"}), 400
|
||||
previous_markdown = siblings[current_index - 1]
|
||||
markdown.order, previous_markdown.order = previous_markdown.order, markdown.order
|
||||
session.commit()
|
||||
return jsonify(markdown.to_dict()), 200
|
||||
|
||||
|
||||
@markdown_bp.route('/move_backward/<int:markdown_id>', methods=['PATCH'])
|
||||
@require_auth(roles=['admin'])
|
||||
@limiter.limit(api.get_rate_limit)
|
||||
def move_backward(markdown_id):
|
||||
with get_db() as session:
|
||||
markdown = session.query(Markdown).get(markdown_id)
|
||||
if not markdown:
|
||||
return jsonify({"error": "file not found"}), 404
|
||||
siblings = session.query(Markdown).filter(Markdown.path_id == markdown.path_id).order_by(Markdown.order).all()
|
||||
current_index = siblings.index(markdown)
|
||||
if current_index == len(siblings) - 1:
|
||||
return jsonify({"error": "already at the last position"}), 400
|
||||
|
||||
next_markdown = siblings[current_index + 1]
|
||||
markdown.order, next_markdown.order = next_markdown.order, next_markdown.order
|
||||
session.commit()
|
||||
return jsonify(markdown.to_dict()), 200
|
||||
|
||||
|
||||
37
api/path.py
37
api/path.py
@@ -110,3 +110,40 @@ def delete_path(path_id):
|
||||
session.commit()
|
||||
return jsonify({"message": "path deleted"}), 200
|
||||
|
||||
|
||||
@path_bp.route('/move_forward/<int:path_id>', methods=['PATCH'])
|
||||
@require_auth(roles=['admin'])
|
||||
@limiter.limit(api.get_rate_limit)
|
||||
def move_forward(path_id):
|
||||
with get_db() as session:
|
||||
path = session.query(Path).get(path_id)
|
||||
if not path:
|
||||
return jsonify({"error": "file not found"}), 404
|
||||
siblings = session.query(Path).filter(Path.parent_id == path.parent_id).order_by(Path.order).all()
|
||||
current_index = siblings.index(path)
|
||||
if current_index == 0:
|
||||
return jsonify({"error": "already at the first position"}), 400
|
||||
previous_path = siblings[current_index - 1]
|
||||
path.order, previous_path.order = previous_path.order, path.order
|
||||
session.commit()
|
||||
return jsonify(path.to_dict()), 200
|
||||
|
||||
|
||||
@path_bp.route('/move_backward/<int:path_id>', methods=['PATCH'])
|
||||
@require_auth(roles=['admin'])
|
||||
@limiter.limit(api.get_rate_limit)
|
||||
def move_backward(path_id):
|
||||
with get_db() as session:
|
||||
path = session.query(Path).get(path_id)
|
||||
if not path:
|
||||
return jsonify({"error": "file not found"}), 404
|
||||
siblings = session.query(Path).filter(Path.parent_id == path.parent_id).order_by(Path.order).all()
|
||||
current_index = siblings.index(path)
|
||||
if current_index == len(siblings) - 1:
|
||||
return jsonify({"error": "already at the last position"}), 400
|
||||
|
||||
next_path = siblings[current_index + 1]
|
||||
path.order, next_path.order = next_path.order, path.order
|
||||
session.commit()
|
||||
return jsonify(path.to_dict()), 200
|
||||
|
||||
|
||||
Reference in New Issue
Block a user