summaryrefslogtreecommitdiff
path: root/api/routes/stations.py
diff options
context:
space:
mode:
authorMatheus <matheus.guedes.mg.m@gmail.com>2025-11-03 08:29:33 -0300
committerMatheus <matheus.guedes.mg.m@gmail.com>2025-11-03 08:29:33 -0300
commit6319a9dc2913f005c735835ac4b46301d6885c64 (patch)
treedb25b78d0013e3cf3c0759575b76dc0bbcc92752 /api/routes/stations.py
parent9e5e5da02b4a9704543e0efd7eb568b31a77a369 (diff)
outros routes
Diffstat (limited to 'api/routes/stations.py')
-rw-r--r--api/routes/stations.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/api/routes/stations.py b/api/routes/stations.py
index e69de29..62e2643 100644
--- a/api/routes/stations.py
+++ b/api/routes/stations.py
@@ -0,0 +1,33 @@
+from fastapi import APIRouter
+from sqlalchemy import select
+from ..database import SessionLocal
+from ..models import Station
+
+router = APIRouter(
+ prefix='/stations',
+ tags=['stations']
+)
+
+@router.get('/')
+async def get_stations():
+ dc = {'stations': []}
+ session = SessionLocal()
+ stmt = select(Station)
+ stations = session.execute(stmt)
+ for station in stations.scalars():
+ stmt_devices = select(SensorDevice.id).where(SensorDevice.station_id == station.id)
+ ids_res = session.execute(stmt_devices).all()
+ ids = []
+ for id in ids_res:
+ ids.append(id.id)
+ stat = {
+ 'id': station.id,
+ 'name': station.name,
+ 'installation_date': station.installation_date,
+ 'location_id': station.location_id,
+ 'is_active': station.is_active,
+ 'sensor_device_ids': ids
+ }
+ dc['stations'].append(stat)
+ dc['size'] = len(dc['stations'])
+ return dc