Compare commits

...

2 Commits

Author SHA1 Message Date
  root 114591d3f4 updated schemas 2 weeks ago
  Lorenzo Pollutri 743eb7122d CORE config proxy API 2 weeks ago
3 changed files with 79 additions and 1 deletions
Split View
  1. +1
    -0
      app.py
  2. +53
    -0
      routes/reslevis.py
  3. +25
    -1
      schemas/reslevis.py

+ 1
- 0
app.py View File

@@ -153,6 +153,7 @@ async def stop_mqtt_monitor():
async def local_then_core(request: Request, call_next):
internal_core_proxy_paths = {
"/reslevis/updateAlarm",
"/reslevis/updateCoreSettings",
}
# only proxy CRUD for Reslevis (change prefix or methods if needed)
if (


+ 53
- 0
routes/reslevis.py View File

@@ -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"}

+ 25
- 1
schemas/reslevis.py View File

@@ -82,6 +82,29 @@ class SettingItem(BaseModel):
debugFields: Optional[List[str]] = None
language: str


class CoreSettingsItem(BaseModel):
ID: int
current_algorithm: str
location_confidence: int
last_seen_threshold: int
beacon_metric_size: int
HA_send_interval: int
HA_send_changes_only: bool
RSSI_enforce_threshold: bool
RSSI_min_threshold: int


class CoreSettingsUpdateItem(BaseModel):
current_algorithm: str
last_seen_threshold: int
beacon_metric_size: int
HA_send_interval: int
HA_send_changes_only: bool
RSSI_enforce_threshold: bool
RSSI_min_threshold: int
location_confidence: Optional[int] = None

class OperatorItem(BaseModel):
id: UUID
name: str
@@ -171,8 +194,9 @@ class TrackHistoryItem(BaseModel):

class TrackerZoneItem(BaseModel):
id: UUID
name: str
zoneList: List[UUID]
tracker: UUID
tracker: List[UUID]
days: Optional[str] = None
time: Optional[str] = None



Loading…
Cancel
Save