summaryrefslogtreecommitdiff
path: root/api/routes/sensors.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/sensors.py
parent9e5e5da02b4a9704543e0efd7eb568b31a77a369 (diff)
outros routes
Diffstat (limited to 'api/routes/sensors.py')
-rw-r--r--api/routes/sensors.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/api/routes/sensors.py b/api/routes/sensors.py
index e69de29..18e0f84 100644
--- a/api/routes/sensors.py
+++ b/api/routes/sensors.py
@@ -0,0 +1,27 @@
+from fastapi import APIRouter
+from sqlalchemy import select
+from ..database import SessionLocal
+from ..models import SensorDevice
+
+router = APIRouter(
+ prefix='/sensors',
+ tags=['sensors']
+)
+
+@router.get('/')
+async def get_sensors():
+ dc = {'sensors': []}
+ session = SessionLocal()
+ stmt = select(SensorDevice)
+ devices = session.execute(stmt)
+ for device in devices.scalars():
+ dev = {
+ 'id': device.id,
+ 'name': device.name,
+ 'installation_date': device.installation_date,
+ 'station_id': device.station_id,
+ 'is_active': device.is_active
+ }
+ dc['sensors'].append(dev)
+ dc['size'] = len(dc['sensors'])
+ return dc