summaryrefslogtreecommitdiff
path: root/api/routes/readings.py
diff options
context:
space:
mode:
Diffstat (limited to 'api/routes/readings.py')
-rw-r--r--api/routes/readings.py28
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
+