Files
sdb2-backend/app/api/v1/main.py
JSC bee1076239
All checks were successful
Backend CI / lint (push) Successful in 9m21s
Backend CI / test (push) Successful in 4m18s
refactor: Improve exception handling and logging in authentication and playlist services; enhance code readability and structure
2025-08-13 00:04:55 +02:00

88 lines
2.4 KiB
Python

"""Main router for v1 endpoints."""
from fastapi import APIRouter
from fastapi.responses import HTMLResponse
from app.core.logging import get_logger
from app.schemas.common import HealthResponse
router = APIRouter()
logger = get_logger(__name__)
@router.get("/")
def health() -> HealthResponse:
"""Health check endpoint."""
logger.info("Health check endpoint accessed")
return HealthResponse(status="healthy")
@router.get("/scalar-docs", response_class=HTMLResponse)
def scalar_docs() -> HTMLResponse:
"""Serve the API documentation using Scalar."""
return """
<!doctype html>
<html>
<head>
<title>API Documentation - Scalar</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<script
id="api-reference"
data-url="http://localhost:8000/api/openapi.json"
src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
</body>
</html>
"""
@router.get("/rapidoc-docs", response_class=HTMLResponse)
async def rapidoc() -> HTMLResponse:
"""Serve the API documentation using Rapidoc."""
return """
<!doctype html>
<html>
<head>
<title>API Documentation - Rapidoc</title>
<meta charset="utf-8">
<script type="module" src="https://unpkg.com/rapidoc/dist/rapidoc-min.js"></script>
</head>
<body>
<rapi-doc
spec-url="http://localhost:8000/api/openapi.json"
theme="dark"
render-style="read">
</rapi-doc>
</body>
</html>
"""
@router.get("/elements-docs", response_class=HTMLResponse)
async def elements_docs() -> HTMLResponse:
"""Serve the API documentation using Stoplight Elements."""
return """
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
>
<title>API Documentation - elements</title>
<script src="https://unpkg.com/@stoplight/elements/web-components.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/@stoplight/elements/styles.min.css">
</head>
<body>
<elements-api
apiDescriptionUrl="http://localhost:8000/api/openapi.json"
router="hash"
/>
</body>
</html>
"""