From c3ab41dd6a4b53b2f0bd332b30e8064abb6d89da Mon Sep 17 00:00:00 2001 From: Karl Date: Thu, 17 Jul 2025 19:06:03 +0100 Subject: [PATCH] test notification --- routes/api.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/routes/api.py b/routes/api.py index e60b200..b768d96 100644 --- a/routes/api.py +++ b/routes/api.py @@ -217,4 +217,27 @@ def send_expiry_notifications_route(username: str, password: str) -> Response: """ from ktvmanager.account_checker import send_expiry_notifications send_expiry_notifications() - return jsonify({"message": "Expiry notifications sent."}) \ No newline at end of file + return jsonify({"message": "Expiry notifications sent."}) + + +@api_blueprint.route("/send-test-notification", methods=["POST"]) +@requires_basic_auth +def send_test_notification_route(username: str, password: str) -> Response: + """Sends a test push notification to the user.""" + user_id = get_user_id_from_username(username) + if not user_id: + return jsonify({"message": "User not found"}), 404 + + subscriptions = get_push_subscriptions(user_id) + if not subscriptions: + return jsonify({"message": "No push subscriptions found for this user."}), 404 + + message_body = json.dumps({"title": "Test Notification", "body": "This is a test notification."}) + + for sub in subscriptions: + try: + send_notification(json.loads(sub['subscription_json']), message_body) + except Exception as e: + print(f"Error sending notification to subscription ID {sub.get('id', 'N/A')}: {e}") + + return jsonify({"message": f"Test notification sent to {len(subscriptions)} subscription(s)."}) \ No newline at end of file