panel.py•1.99 kB
"""
API routes for panel configuration.
"""
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.ext.asyncio import AsyncSession
from typing import Dict, Any, List
from src.database.database import get_db
from src.database import crud
from src.config.models import PanelConfiguration
from src.config.config_manager import ConfigManager
router = APIRouter(
prefix="/panel",
tags=["panel"],
)
config_manager = ConfigManager()
@router.get("/", response_model=Dict[str, Any])
async def get_panel_config(db: AsyncSession = Depends(get_db)):
"""Get the panel configuration."""
panel = await crud.get_panel_config(db)
if not panel:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="Panel configuration not found"
)
return {
"name": panel.name,
"version": panel.version,
"config_schema_version": panel.config_schema_version,
"global_settings": panel.global_settings
}
@router.put("/", response_model=Dict[str, Any])
async def update_panel_config(
config_data: Dict[str, Any],
db: AsyncSession = Depends(get_db)
):
"""Update the panel configuration."""
try:
panel = await crud.update_panel_config(db, config_data)
return {
"name": panel.name,
"version": panel.version,
"config_schema_version": panel.config_schema_version,
"global_settings": panel.global_settings
}
except Exception as e:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail=f"Failed to update panel configuration: {str(e)}"
)
@router.get("/schema", response_model=Dict[str, Any])
async def get_config_schema():
"""Get the configuration schema."""
return config_manager.schema
@router.get("/health", response_model=Dict[str, str])
async def health_check():
"""Health check endpoint."""
return {"status": "healthy"}