blob: 18e0f84f2a1a33bac3442e58aefa1268b95ce99e (
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
|
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
|