Procházet zdrojové kódy

Updated schema to match new core field

master
Lorenzo Pollutri před 5 hodinami
rodič
revize
95f102987e
2 změnil soubory, kde provedl 46 přidání a 1 odebrání
  1. +44
    -1
      routes/reslevis.py
  2. +2
    -0
      schemas/reslevis.py

+ 44
- 1
routes/reslevis.py Zobrazit soubor

@@ -3,6 +3,7 @@ import json
import os
import tempfile
from urllib.parse import urlencode
from uuid import UUID

from fastapi import APIRouter, Depends, File, Form, HTTPException, Query, Request, UploadFile
import httpx
@@ -176,6 +177,48 @@ def _uid_from_claims(claims: dict) -> str:
return str(uid)


def _uuid_or_none(value):
if value in ("", None, 0, "0"):
return None
try:
return str(UUID(str(value)))
except (TypeError, ValueError, AttributeError):
return None


def _operator_uuid_by_name(value):
name = str(value).strip()
if not name:
return None

try:
rows = operator_repo.list()
except Exception:
return None

target = name.lower()
for row in rows:
if not isinstance(row, dict):
continue
if str(row.get("name") or "").strip().lower() == target:
return _uuid_or_none(row.get("id"))
return None


def _normalize_alarm_core(row: dict) -> dict:
row = dict(row)
operator_raw = row.get("operator")
operator_uuid = _uuid_or_none(operator_raw)

if operator_uuid is None and operator_raw not in ("", None, 0, "0"):
operator_uuid = _operator_uuid_by_name(operator_raw)
if operator_uuid is None and not row.get("operatorName"):
row["operatorName"] = str(operator_raw)

row["operator"] = operator_uuid
return row


def _floor_maps_index_path() -> str:
return os.path.join(config_env.RESLEVIS_MAPS_DIR, "maps.json")

@@ -626,7 +669,7 @@ async def getAlarms():
if not isinstance(payload, list):
raise HTTPException(status_code=502, detail="Unexpected CORE response type")

return payload
return [_normalize_alarm_core(row) for row in payload if isinstance(row, dict)]


@router.put(


+ 2
- 0
schemas/reslevis.py Zobrazit soubor

@@ -176,6 +176,8 @@ class AlarmCoreItem(BaseModel):
status: str
timestamp: str
operator: Optional[UUID] = None
operatorName: Optional[str] = None
assignment_timestamp: Optional[str] = None
resolution_timestamp: Optional[str] = None




Načítá se…
Zrušit
Uložit