add: backup version converter/ backup logic 1.0

This commit is contained in:
h z
2025-04-25 13:00:41 +01:00
parent 35c8934963
commit 84494827ad
15 changed files with 2107 additions and 76 deletions

View File

@@ -22,6 +22,22 @@ def inflate_template(template):
@template_bp.route('/markdown/<int:template_id>', methods=['GET'])
@etag_response
def get_markdown_template(template_id):
"""
Get a specific markdown template by ID.
This endpoint retrieves a markdown template by its ID.
The template is inflated to include any nested templates.
Request:
- template_id (int): The ID of the template to retrieve
Returns:
A JSON object containing the markdown template.
Response Codes:
- 200: Success
- 204: No content (template not found)
"""
with get_db() as session:
template = session.query(MarkdownTemplate).get(template_id)
if template is None:
@@ -32,6 +48,18 @@ def get_markdown_template(template_id):
@template_bp.route('/markdown/', methods=['GET'])
@etag_response
def get_markdown_templates():
"""
List all markdown templates.
This endpoint retrieves a list of all markdown templates in the system.
Each template is inflated to include any nested templates.
Returns:
A JSON array containing all markdown templates.
Response Codes:
- 200: Success
"""
with get_db() as session:
templates = session.query(MarkdownTemplate).all()
print(templates)
@@ -41,6 +69,24 @@ def get_markdown_templates():
@template_bp.route('/markdown/', methods=['POST'])
@require_auth(roles=['admin'])
def create_markdown_template():
"""
Create a new markdown template.
This endpoint creates a new markdown template with the provided data.
It requires authentication with the 'admin' role.
Request:
- title (str): The title of the template (required)
- parameters (object, optional): The parameters for the template
- layout (str, optional): The layout content of the template
Returns:
A JSON object containing the created template.
Response Codes:
- 200: Created successfully
- 400: Bad request (missing title or other error)
"""
data = request.json
if "title" not in data:
return jsonify({"error": "title is missing"}), 400
@@ -60,6 +106,25 @@ def create_markdown_template():
@template_bp.route('/markdown/<int:template_id>', methods=['PUT', 'PATCH'])
@require_auth(roles=['admin'])
def update_markdown_template(template_id):
"""
Update a markdown template.
This endpoint updates an existing markdown template with the provided data.
It requires authentication with the 'admin' role.
Request:
- template_id (int): The ID of the template to update
- title (str, optional): The new title for the template
- parameters (object, optional): The new parameters for the template
- layout (str, optional): The new layout content for the template
Returns:
A JSON object containing the updated template.
Response Codes:
- 200: Updated successfully
- 400: Bad request (template not found)
"""
data = request.json
with get_db() as session:
template = session.query(MarkdownTemplate).get(template_id)
@@ -80,6 +145,22 @@ def update_markdown_template(template_id):
@template_bp.route('/markdown/<int:template_id>', methods=['DELETE'])
@require_auth(roles=['admin'])
def delete_markdown_template(template_id):
"""
Delete a markdown template.
This endpoint deletes an existing markdown template.
It requires authentication with the 'admin' role.
Request:
- template_id (int): The ID of the template to delete
Returns:
A JSON object with a success message.
Response Codes:
- 200: Deleted successfully
- 400: Bad request (template not found)
"""
with get_db() as session:
template = session.query(MarkdownTemplate).get(template_id)
if template is None:
@@ -89,4 +170,3 @@ def delete_markdown_template(template_id):
if template_id in cached_templates.keys():
cached_templates.pop(template_id)
return jsonify({'message': 'deleted'}), 200

View File

@@ -9,6 +9,21 @@ from db.models.PathTemplate import PathTemplate
@template_bp.route('/path/<int:template_id>', methods=['GET'])
@etag_response
def get_path_template(template_id):
"""
Get a specific path template by ID.
This endpoint retrieves a path template by its ID.
Request:
- template_id (int): The ID of the template to retrieve
Returns:
A JSON object containing the path template.
Response Codes:
- 200: Success
- 204: No content (template not found)
"""
with get_db() as session:
template = session.query(PathTemplate).get(template_id)
if template is None:
@@ -18,6 +33,17 @@ def get_path_template(template_id):
@template_bp.route('/path/', methods=['GET'])
@etag_response
def get_path_templates():
"""
List all path templates.
This endpoint retrieves a list of all path templates in the system.
Returns:
A JSON array containing all path templates.
Response Codes:
- 200: Success
"""
with get_db() as session:
templates = session.query(PathTemplate).all()
return jsonify([template.to_dict() for template in templates]), 200
@@ -26,6 +52,23 @@ def get_path_templates():
@template_bp.route('/path/', methods=['POST'])
@require_auth(roles=['admin'])
def create_path_template():
"""
Create a new path template.
This endpoint creates a new path template with the provided data.
It requires authentication with the 'admin' role.
Request:
- title (str): The title of the template (required)
- structure (str): The structure definition for the template
Returns:
A JSON object containing the created template.
Response Codes:
- 200: Created successfully
- 400: Bad request (missing title or other error)
"""
data = request.json
if "title" not in data:
return jsonify({"error": "title is missing"}), 400
@@ -44,6 +87,24 @@ def create_path_template():
@template_bp.route('/path/<int:template_id>', methods=['PUT', 'PATCH'])
@require_auth(roles=['admin'])
def update_path_template(template_id):
"""
Update a path template.
This endpoint updates an existing path template with the provided data.
It requires authentication with the 'admin' role.
Request:
- template_id (int): The ID of the template to update
- title (str, optional): The new title for the template
- structure (str, optional): The new structure definition for the template
Returns:
A JSON object containing the updated template.
Response Codes:
- 200: Updated successfully
- 400: Bad request (template not found)
"""
data = request.json
with get_db() as session:
template = session.query(PathTemplate).get(template_id)
@@ -60,6 +121,22 @@ def update_path_template(template_id):
@template_bp.route('/path/<int:template_id>', methods=['DELETE'])
@require_auth(roles=['admin'])
def delete_path_template(template_id):
"""
Delete a path template.
This endpoint deletes an existing path template.
It requires authentication with the 'admin' role.
Request:
- template_id (int): The ID of the template to delete
Returns:
A JSON object with a success message.
Response Codes:
- 200: Deleted successfully
- 400: Bad request (template not found)
"""
with get_db() as session:
template = session.query(PathTemplate).get(template_id)
if template is None: