40 lines
982 B
Python
40 lines
982 B
Python
"""
|
|
app/api/routes_config.py
|
|
HTTP endpoints for reading and updating runtime configuration.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from fastapi import APIRouter
|
|
|
|
from app.models import ConfigResponse, UpdateConfigRequest
|
|
from app.services import config_service, event_service
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
router = APIRouter(prefix="/api/config", tags=["config"])
|
|
|
|
|
|
@router.get("", response_model=ConfigResponse)
|
|
def get_config():
|
|
return config_service.get_config()
|
|
|
|
|
|
@router.patch("", response_model=ConfigResponse)
|
|
def update_config(body: UpdateConfigRequest):
|
|
cfg = config_service.update_config(
|
|
default_wait_seconds=body.default_wait_seconds,
|
|
default_empty_response=body.default_empty_response,
|
|
)
|
|
event_service.broadcast(
|
|
"config.updated",
|
|
{
|
|
"default_wait_seconds": cfg.default_wait_seconds,
|
|
"default_empty_response": cfg.default_empty_response,
|
|
},
|
|
)
|
|
return cfg
|
|
|