bmc_hub/patch_backend_router.py
Christian ceb560e2f2 feat: Add bottom bar functionality with real-time updates and manual endpoint tests
- Implemented a new bottom bar feature in `bottom-bar.js` that fetches and displays various notifications and statuses in real-time.
- Added functions for handling visibility, state updates, and user interactions within the bottom bar.
- Introduced WebSocket connection for real-time updates and fallback polling mechanism.
- Created a manual testing script `test_manual.py` to validate API endpoints for the manual module.
- Included tests for various paths to ensure expected responses from the server.
2026-04-12 02:27:01 +02:00

36 lines
1.3 KiB
Python

import re
with open("app/modules/manual/backend/router.py", "r") as f:
content = f.read()
if "from fastapi import" in content and "BackgroundTasks" not in content:
content = content.replace("from fastapi import ", "from fastapi import BackgroundTasks, ")
if "def get_manual_article(slug: str):" in content:
content = content.replace("def get_manual_article(slug: str):", "def get_manual_article(slug: str, background_tasks: BackgroundTasks):")
bg_def = """
def _increment_use_count(manual_id: str):
try:
execute_query(
"UPDATE manual_articles SET use_count = COALESCE(use_count, 0) + 1 WHERE id = %s",
(manual_id,)
)
except Exception as e:
logger.error(f"Failed to increment use_count for manual {manual_id}: {e}")
@router.get("/{slug}")
"""
content = content.replace('@router.get("/{slug}")', bg_def)
target_inc = """ execute_query(
"UPDATE manual_articles SET use_count = COALESCE(use_count, 0) + 1 WHERE id = %s",
(article["id"],),
)"""
new_inc = """ # Increment view async to save latency
background_tasks.add_task(_increment_use_count, article["id"])"""
content = content.replace(target_inc, new_inc)
with open("app/modules/manual/backend/router.py", "w") as f:
f.write(content)