43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
from typing import Any
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
from psycopg import AsyncConnection
|
|
|
|
from app.auth.project_dependencies import get_project_pg_connection
|
|
from app.domain.schemas.scada import ScadaDeviceResponse
|
|
from app.infra.db.postgresql.scada import ScadaInfoRepository, get_scada_info_schema
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/network-schemas/scada-device", summary="获取 SCADA 设备结构")
|
|
def get_scada_device_schema() -> dict[str, dict[str, Any]]:
|
|
return get_scada_info_schema("")
|
|
|
|
|
|
@router.get(
|
|
"/scada-devices",
|
|
summary="获取 SCADA 设备列表",
|
|
response_model=list[ScadaDeviceResponse],
|
|
)
|
|
async def get_scada_devices(
|
|
conn: AsyncConnection = Depends(get_project_pg_connection),
|
|
) -> list[dict[str, Any]]:
|
|
return await ScadaInfoRepository.get_scadas(conn)
|
|
|
|
|
|
@router.get(
|
|
"/scada-devices/{device_id}",
|
|
summary="获取 SCADA 设备",
|
|
response_model=ScadaDeviceResponse,
|
|
)
|
|
async def get_scada_device(
|
|
device_id: str,
|
|
conn: AsyncConnection = Depends(get_project_pg_connection),
|
|
) -> dict[str, Any]:
|
|
device = await ScadaInfoRepository.get_scada(conn, device_id)
|
|
if device is None:
|
|
raise HTTPException(status_code=404, detail="SCADA 设备不存在")
|
|
return device
|