|
|
|
@@ -23,6 +23,8 @@ from schemas.reslevis import ( |
|
|
|
TrackHistoryItem, |
|
|
|
TrackerZoneItem, |
|
|
|
SettingItem, |
|
|
|
CoreSettingsItem, |
|
|
|
CoreSettingsUpdateItem, |
|
|
|
) |
|
|
|
|
|
|
|
from logica_reslevis.gateway import GatewayJsonRepository |
|
|
|
@@ -44,6 +46,7 @@ from security import get_current_user |
|
|
|
CORE_BASE_URL = config_env.CORE_API_URL.rstrip("/") |
|
|
|
ALERTS_CORE_BASE_URL = "http://localhost:1902" |
|
|
|
TRACKS_CORE_BASE_URL = "http://localhost:1902" |
|
|
|
SETTINGS_CORE_BASE_URL = "http://127.0.0.1:1902" |
|
|
|
CORE_TIMEOUT = 2.0 # secondi |
|
|
|
|
|
|
|
async def sync_core_get(request: Request) -> None: |
|
|
|
@@ -591,3 +594,53 @@ def updateSetting(item: SettingItem): |
|
|
|
def removeSetting(setting_id: str): |
|
|
|
setting_repo.remove(setting_id) |
|
|
|
return {"message": "OK"} |
|
|
|
|
|
|
|
|
|
|
|
@router.get( |
|
|
|
"/getCoreSettings", |
|
|
|
response_model=List[CoreSettingsItem], |
|
|
|
tags=["Reslevis"], |
|
|
|
dependencies=[Depends(get_current_user)], |
|
|
|
) |
|
|
|
async def getCoreSettings(): |
|
|
|
async with httpx.AsyncClient(timeout=CORE_TIMEOUT) as client: |
|
|
|
resp = await client.get(f"{SETTINGS_CORE_BASE_URL}/reslevis/settings") |
|
|
|
|
|
|
|
if resp.status_code >= 400: |
|
|
|
detail = resp.text.strip() or "CORE settings request failed" |
|
|
|
raise HTTPException(status_code=resp.status_code, detail=detail) |
|
|
|
|
|
|
|
try: |
|
|
|
payload = resp.json() |
|
|
|
except ValueError as exc: |
|
|
|
raise HTTPException(status_code=502, detail="Invalid CORE response") from exc |
|
|
|
|
|
|
|
if not isinstance(payload, list): |
|
|
|
raise HTTPException(status_code=502, detail="Unexpected CORE response type") |
|
|
|
|
|
|
|
return payload |
|
|
|
|
|
|
|
|
|
|
|
@router.put( |
|
|
|
"/updateCoreSettings", |
|
|
|
tags=["Reslevis"], |
|
|
|
dependencies=[Depends(get_current_user)], |
|
|
|
) |
|
|
|
async def updateCoreSettings(item: CoreSettingsUpdateItem): |
|
|
|
async with httpx.AsyncClient(timeout=CORE_TIMEOUT) as client: |
|
|
|
resp = await client.patch( |
|
|
|
f"{SETTINGS_CORE_BASE_URL}/reslevis/settings", |
|
|
|
json=item.model_dump(exclude_none=True), |
|
|
|
) |
|
|
|
|
|
|
|
if resp.status_code >= 400: |
|
|
|
detail = resp.text.strip() or "CORE settings update failed" |
|
|
|
raise HTTPException(status_code=resp.status_code, detail=detail) |
|
|
|
|
|
|
|
if not resp.content: |
|
|
|
return {"message": "OK"} |
|
|
|
|
|
|
|
try: |
|
|
|
return resp.json() |
|
|
|
except ValueError: |
|
|
|
return {"message": "OK"} |