diff options
| author | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-11-03 08:29:33 -0300 |
|---|---|---|
| committer | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-11-03 08:29:33 -0300 |
| commit | 6319a9dc2913f005c735835ac4b46301d6885c64 (patch) | |
| tree | db25b78d0013e3cf3c0759575b76dc0bbcc92752 /api/routes/readings.py | |
| parent | 9e5e5da02b4a9704543e0efd7eb568b31a77a369 (diff) | |
outros routes
Diffstat (limited to 'api/routes/readings.py')
| -rw-r--r-- | api/routes/readings.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/api/routes/readings.py b/api/routes/readings.py index e69de29..957106c 100644 --- a/api/routes/readings.py +++ b/api/routes/readings.py @@ -0,0 +1,28 @@ +from fastapi import APIRouter +from sqlalchemy import select +from ..database import SessionLocal +from ..models import Reading + +router = APIRouter( + prefix='/readings', + tags=['readings'] +) + +@router.get('/') +async def get_readings(): + dc = {'readings': []} + session = SessionLocal() + stmt = select(Reading) + readings = session.execute(stmt) + for reading in readings.scalars(): + re = { + 'id': reading.id, + 'sensor_device_id': reading.sensor_device_id, + 'measure_id': reading.measure_id, + 'value': reading.value, + 'time': reading.time + } + dc['readings'].append(re) + dc['size'] = len(dc['readings']) + return dc + |
