manage markdowns by path
This commit is contained in:
@@ -18,6 +18,13 @@ def get_markdowns():
|
||||
mds = db.query(Markdown).all()
|
||||
return jsonify([md.to_dict() for md in mds]), 200
|
||||
|
||||
@markdown_bp.route('/by_path/<int:path_id>', methods=['GET'])
|
||||
@limiter.limit('5 per minute')
|
||||
def get_markdowns_by_path(path_id):
|
||||
with get_db() as db:
|
||||
markdowns = db.query(Markdown).filter(Markdown.path_id == path_id).all()
|
||||
return jsonify([md.to_dict() for md in markdowns]), 200
|
||||
|
||||
|
||||
|
||||
@markdown_bp.route('/<int:markdown_id>', methods=['GET'])
|
||||
@@ -36,10 +43,10 @@ def create_markdown():
|
||||
data = request.json
|
||||
title = data.get('title')
|
||||
content = data.get('content')
|
||||
path = data.get('path')
|
||||
path_id = data.get('path_id')
|
||||
if not title or not content:
|
||||
return jsonify({"error": "missing required fields"}), 400
|
||||
new_markdown = Markdown(title=title, content=content, path=path)
|
||||
new_markdown = Markdown(title=title, content=content, path_id=path_id)
|
||||
with get_db() as db:
|
||||
try:
|
||||
db.add(new_markdown)
|
||||
@@ -62,7 +69,7 @@ def update_markdown(markdown_id):
|
||||
data = request.json
|
||||
markdown.title = data.get('title')
|
||||
markdown.content = data.get('content')
|
||||
markdown.path = data.get('path')
|
||||
markdown.path_id = data.get('path_id')
|
||||
db.commit()
|
||||
return jsonify(markdown.to_dict()), 200
|
||||
|
||||
|
||||
Reference in New Issue
Block a user