From 6319a9dc2913f005c735835ac4b46301d6885c64 Mon Sep 17 00:00:00 2001 From: Matheus Date: Mon, 3 Nov 2025 08:29:33 -0300 Subject: outros routes --- api/routes/readings.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'api/routes/readings.py') 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 + -- cgit v1.2.3