bmc_hub/app/modules/wiki/backend/router.py
Christian 3d7fb1aa48 feat(migrations): add AnyDesk session management and customer wiki slug updates
- Created migration scripts for AnyDesk sessions and hardware assets.
- Implemented apply_migration_115.py to execute migration for AnyDesk sessions.
- Added set_customer_wiki_slugs.py script to update customer wiki slugs based on a predefined folder list.
- Developed run_migration.py to apply AnyDesk migration schema.
- Added tests for Service Contract Wizard to ensure functionality and dry-run mode.
2026-02-10 14:40:38 +01:00

55 lines
1.5 KiB
Python

"""
Wiki.js Integration API Router (read-only)
"""
import logging
from typing import Optional
from fastapi import APIRouter, HTTPException, Query
from app.core.config import settings
from app.core.database import execute_query_single
from app.modules.wiki.backend.service import WikiService
from app.modules.wiki.models.schemas import WikiPageResponse
logger = logging.getLogger(__name__)
router = APIRouter()
service = WikiService()
@router.get("/customers/{customer_id}/pages", response_model=WikiPageResponse)
async def list_customer_wiki_pages(
customer_id: int,
tag: Optional[str] = Query(None),
query: Optional[str] = Query(None),
limit: int = Query(20, ge=1, le=100),
):
customer = execute_query_single(
"SELECT id, name, wiki_slug FROM customers WHERE id = %s",
(customer_id,),
)
if not customer:
raise HTTPException(status_code=404, detail="Customer not found")
wiki_slug = (customer.get("wiki_slug") or "").strip()
effective_tag = tag
if not effective_tag and not (query or "").strip():
effective_tag = "guide"
if not wiki_slug:
return WikiPageResponse(
pages=[],
path="/en/Kunder",
tag=effective_tag,
query=query,
base_url=settings.WIKI_BASE_URL,
)
payload = await service.list_customer_pages(
slug=wiki_slug,
tag=effective_tag,
query=query,
limit=limit,
)
return WikiPageResponse(**payload)