Skip to content
Snippets Groups Projects
Commit fefc3bdf authored by Robert Goldmann's avatar Robert Goldmann
Browse files

externalized query specifications

parent e8555328
Branches
Tags
No related merge requests found
import secrets import secrets
from fastapi import Security, HTTPException from fastapi import Security, HTTPException, Query
from fastapi.security import APIKeyHeader from fastapi.security import APIKeyHeader
from starlette.status import HTTP_403_FORBIDDEN from starlette.status import HTTP_403_FORBIDDEN
...@@ -23,3 +23,9 @@ async def check_api_key(apiKey: str = Security(API_KEY_HEADER)): ...@@ -23,3 +23,9 @@ async def check_api_key(apiKey: str = Security(API_KEY_HEADER)):
expectedApiKey = SETTINGS['api']['key'] expectedApiKey = SETTINGS['api']['key']
if not secrets.compare_digest(expectedApiKey, apiKey): if not secrets.compare_digest(expectedApiKey, apiKey):
raise HTTPException(status_code=HTTP_403_FORBIDDEN, detail='apiKey invalid') 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.')
from typing import List from typing import List
from fastapi import APIRouter, HTTPException, Depends, Query from fastapi import APIRouter, HTTPException, Depends
from sqlalchemy.orm import Session 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 import Schemas, Crud
from logic.databaseNew.Schemas import Status from logic.databaseNew.Schemas import Status
...@@ -14,13 +14,10 @@ router = APIRouter( ...@@ -14,13 +14,10 @@ router = APIRouter(
@router.get('/', response_model=List[Schemas.Measurement], @router.get('/', response_model=List[Schemas.Measurement],
summary='Gets all measurements (Number of results can be limited by specifying a date range).') summary='Gets all measurements',
async def read_measurements(startDateTime: str = Query('2020-01-20 18:15:22', description='Number of results can be limited by specifying a date range')
description='The start date and time of the date range ' async def read_measurements(startDateTime: str = START_DATE_TIME,
'that should be taken into account.'), endDateTime: str = END_DATE_TIME,
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.'),
db: Session = Depends(get_database)): db: Session = Depends(get_database)):
return Crud.get_measurements(db, startDateTime=startDateTime, endDateTime=endDateTime) return Crud.get_measurements(db, startDateTime=startDateTime, endDateTime=endDateTime)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment