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

@@ -9,6 +9,18 @@ webhook_bp = Blueprint('webhook', __name__, url_prefix='/api/webhook')
@webhook_bp.route('/', methods=['GET'])
@require_auth(roles=['admin'])
def list_webhooks():
"""
List all webhooks.
This endpoint retrieves a list of all webhooks in the system.
It requires authentication with the 'admin' role.
Returns:
A JSON array containing all webhooks.
Response Codes:
- 200: Success
"""
with get_db() as session:
hooks = session.query(Webhook).all()
return jsonify([h.to_dict() for h in hooks]), 200
@@ -17,6 +29,23 @@ def list_webhooks():
@webhook_bp.route('/', methods=['POST'])
@require_auth(['admin'])
def create_webhook():
"""
Create a new webhook.
This endpoint creates a new webhook with the provided URL.
It requires authentication with the 'admin' role.
Request:
- hook_url (str): The URL of the webhook
Returns:
A JSON object containing the created webhook.
Response Codes:
- 201: Created successfully
- 400: Bad request (hook_url is missing)
- 409: Conflict (webhook URL already exists)
"""
data = request.json
hook_url = data.get('hook_url')
if not hook_url:
@@ -35,6 +64,25 @@ def create_webhook():
@webhook_bp.route('/<int:webhook_id>', methods=['PUT', 'PATCH'])
@require_auth(roles=['admin'])
def update_webhook(webhook_id):
"""
Update a webhook.
This endpoint updates an existing webhook with the provided URL.
It requires authentication with the 'admin' role.
Request:
- webhook_id (int): The ID of the webhook to update
- hook_url (str): The new URL for the webhook
Returns:
A JSON object containing the updated webhook.
Response Codes:
- 200: Updated successfully
- 400: Bad request (hook_url is missing)
- 404: Webhook not found
- 409: Conflict (webhook URL already exists)
"""
data = request.json
if 'hook_url' not in data:
return jsonify({'error': 'hook_url is required'}), 400
@@ -56,6 +104,22 @@ def update_webhook(webhook_id):
@webhook_bp.route('/<int:webhook_id>', methods=['DELETE'])
@require_auth(roles=['admin'])
def delete_webhook(webhook_id):
"""
Delete a webhook.
This endpoint deletes an existing webhook.
It requires authentication with the 'admin' role.
Request:
- webhook_id (int): The ID of the webhook to delete
Returns:
A JSON object with a success message.
Response Codes:
- 200: Deleted successfully
- 404: Webhook not found
"""
with get_db() as session:
webhook = session.query(Webhook).get(webhook_id)
if not webhook:
@@ -63,4 +127,4 @@ def delete_webhook(webhook_id):
session.delete(webhook)
session.commit()
return jsonify({'message': 'Webhook deleted'}), 200
return jsonify({'message': 'Webhook deleted'}), 200