diff --git a/src/Dependencies.py b/src/Dependencies.py index 0fe8160b864378bbb93232ad93a31727976c4542..1293c4753f6833e3d7f5294f04e7df5fdc33fdaa 100644 --- a/src/Dependencies.py +++ b/src/Dependencies.py @@ -1,6 +1,6 @@ import secrets -from fastapi import Security, HTTPException +from fastapi import Security, HTTPException, Query from fastapi.security import APIKeyHeader from starlette.status import HTTP_403_FORBIDDEN @@ -23,3 +23,9 @@ async def check_api_key(apiKey: str = Security(API_KEY_HEADER)): expectedApiKey = SETTINGS['api']['key'] if not secrets.compare_digest(expectedApiKey, apiKey): raise HTTPException(status_code=HTTP_403_FORBIDDEN, detail='apiKey invalid') + + +START_DATE_TIME: str = Query('2021-01-16 18:15:22', + description='The start date and time of the date range that should be taken into account.') +END_DATE_TIME: str = Query('2021-01-16 19:15:22', + description='The end date and time of the date range that should be taken into account.') diff --git a/src/routers/MeasurementRouter.py b/src/routers/MeasurementRouter.py index ad83be2413d50c5307d5dd02b8613b79adaabfc3..9286d75d60586e575c7f2a5c18f56a22e6ab723c 100644 --- a/src/routers/MeasurementRouter.py +++ b/src/routers/MeasurementRouter.py @@ -1,9 +1,9 @@ from typing import List -from fastapi import APIRouter, HTTPException, Depends, Query +from fastapi import APIRouter, HTTPException, Depends from sqlalchemy.orm import Session -from Dependencies import get_database, check_api_key +from Dependencies import get_database, check_api_key, START_DATE_TIME, END_DATE_TIME from logic.databaseNew import Schemas, Crud from logic.databaseNew.Schemas import Status @@ -14,13 +14,10 @@ router = APIRouter( @router.get('/', response_model=List[Schemas.Measurement], - summary='Gets all measurements (Number of results can be limited by specifying a date range).') -async def read_measurements(startDateTime: str = Query('2020-01-20 18:15:22', - description='The start date and time of the date range ' - 'that should be taken into account.'), - endDateTime: str = Query('2020-01-20 19:15:22', - description='The end date and time of the date range ' - 'that should be taken into account.'), + summary='Gets all measurements', + description='Number of results can be limited by specifying a date range') +async def read_measurements(startDateTime: str = START_DATE_TIME, + endDateTime: str = END_DATE_TIME, db: Session = Depends(get_database)): return Crud.get_measurements(db, startDateTime=startDateTime, endDateTime=endDateTime)