Сравнить коммиты

...

2 коммитов

Автор SHA1 Сообщение Дата
  root 114591d3f4 updated schemas 2 недель назад
  Lorenzo Pollutri 743eb7122d CORE config proxy API 2 недель назад
3 измененных файлов: 79 добавлений и 1 удалений
  1. +1
    -0
      app.py
  2. +53
    -0
      routes/reslevis.py
  3. +25
    -1
      schemas/reslevis.py

+ 1
- 0
app.py Просмотреть файл

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


+ 53
- 0
routes/reslevis.py Просмотреть файл

@@ -23,6 +23,8 @@ from schemas.reslevis import (
TrackHistoryItem, TrackHistoryItem,
TrackerZoneItem, TrackerZoneItem,
SettingItem, SettingItem,
CoreSettingsItem,
CoreSettingsUpdateItem,
) )


from logica_reslevis.gateway import GatewayJsonRepository 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("/") CORE_BASE_URL = config_env.CORE_API_URL.rstrip("/")
ALERTS_CORE_BASE_URL = "http://localhost:1902" ALERTS_CORE_BASE_URL = "http://localhost:1902"
TRACKS_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 CORE_TIMEOUT = 2.0 # secondi


async def sync_core_get(request: Request) -> None: async def sync_core_get(request: Request) -> None:
@@ -591,3 +594,53 @@ def updateSetting(item: SettingItem):
def removeSetting(setting_id: str): def removeSetting(setting_id: str):
setting_repo.remove(setting_id) setting_repo.remove(setting_id)
return {"message": "OK"} 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 Просмотреть файл

@@ -82,6 +82,29 @@ class SettingItem(BaseModel):
debugFields: Optional[List[str]] = None debugFields: Optional[List[str]] = None
language: str 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): class OperatorItem(BaseModel):
id: UUID id: UUID
name: str name: str
@@ -171,8 +194,9 @@ class TrackHistoryItem(BaseModel):


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




Загрузка…
Отмена
Сохранить