Influx related functionality finished
This commit is contained in:
0
api/__init__.py
Normal file
0
api/__init__.py
Normal file
33
api/testAPI.py
Normal file
33
api/testAPI.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from fastapi import (
|
||||
APIRouter,
|
||||
status,
|
||||
Body, Depends)
|
||||
from influxdb_client.client.influxdb_client_async import InfluxDBClientAsync
|
||||
from influx_related import get_influxdb_client, get_influx_data, write_influx_data
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.get(
|
||||
path="/get_influx/",
|
||||
name='get data from influxdb, last one hour',
|
||||
#response_model=InfluxDBClientAsync,
|
||||
responses={
|
||||
status.HTTP_401_UNAUTHORIZED: {},
|
||||
}
|
||||
)
|
||||
async def get_influx(client: InfluxDBClientAsync = Depends(get_influxdb_client)):
|
||||
return {'results': await get_influx_data(client)}
|
||||
|
||||
@router.post(
|
||||
path="/write_influx/",
|
||||
name='write data to influxdb',
|
||||
#response_model=InfluxDBClientAsync,
|
||||
responses={
|
||||
status.HTTP_401_UNAUTHORIZED: {},
|
||||
}
|
||||
)
|
||||
async def write_influx(temp: float, client: InfluxDBClientAsync = Depends(get_influxdb_client)):
|
||||
await write_influx_data(client, temp)
|
||||
return {"status": "OK"}
|
||||
|
||||
Reference in New Issue
Block a user