blob: 59af328912c463f28e63e0de9fee7cf901ad9786 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
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'])
session.close()
return dc
|