Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
StorageLeaf
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ProjectLeaf
StorageLeaf
Commits
fefc3bdf
Commit
fefc3bdf
authored
4 years ago
by
Robert Goldmann
Browse files
Options
Downloads
Patches
Plain Diff
externalized query specifications
parent
e8555328
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Dependencies.py
+7
-1
7 additions, 1 deletion
src/Dependencies.py
src/routers/MeasurementRouter.py
+6
-9
6 additions, 9 deletions
src/routers/MeasurementRouter.py
with
13 additions
and
10 deletions
src/Dependencies.py
+
7
−
1
View file @
fefc3bdf
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.
'
)
This diff is collapsed.
Click to expand it.
src/routers/MeasurementRouter.py
+
6
−
9
View file @
fefc3bdf
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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment