Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
aura-engine
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Lars Kruse
aura-engine
Commits
dca25472
Commit
dca25472
authored
5 years ago
by
David Trattnig
Browse files
Options
Downloads
Patches
Plain Diff
Improved API response code handling.
parent
a4820ed5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
api.py
+22
-2
22 additions, 2 deletions
api.py
with
22 additions
and
2 deletions
api.py
+
22
−
2
View file @
dca25472
...
...
@@ -35,10 +35,12 @@ from flask_cors import CORS
from
flask_sqlalchemy
import
SQLAlchemy
from
flask_marshmallow
import
Marshmallow
from
marshmallow
import
Schema
,
fields
,
post_dump
from
flask_restful
import
Api
,
Resource
from
flask_restful
import
Api
,
Resource
,
abort
from
apispec
import
APISpec
from
apispec.ext.marshmallow
import
MarshmallowPlugin
from
apispec_webframeworks.flask
import
FlaskPlugin
# import werkzeug
from
werkzeug.exceptions
import
HTTPException
,
default_exceptions
,
Aborter
from
libraries.base.logger
import
AuraLogger
from
libraries.base.config
import
AuraConfig
...
...
@@ -62,12 +64,21 @@ app.config["CACHE_TYPE"] = "simple"
app
.
config
[
"
CACHE_DEFAULT_TIMEOUT
"
]
=
0
app
.
config
[
'
SEND_FILE_MAX_AGE_DEFAULT
'
]
=
0
cache
=
Cache
(
app
)
cors
=
CORS
(
app
,
resources
=
{
r
"
/*
"
:
{
"
origins
"
:
"
*
"
}})
cors
=
CORS
(
app
,
resources
=
{
r
"
/*
"
:
{
"
origins
"
:
"
*
"
}})
# FIXME Update CORS for production use
db
=
SQLAlchemy
(
app
)
ma
=
Marshmallow
(
app
)
api
=
Api
(
app
)
#
# Werkzeug HTTP code mappings
#
class
NoDataAvailable
(
HTTPException
):
code
=
204
description
=
"
There is currently no content available.
"
default_exceptions
[
204
]
=
NoDataAvailable
abort
=
Aborter
()
class
EngineApi
:
"""
...
...
@@ -95,6 +106,7 @@ class EngineApi:
spec
.
components
.
schema
(
"
TrackService
"
,
schema
=
TrackServiceSchema
)
# Schema instances
EngineApi
.
trackservice_schema
=
TrackServiceSchema
(
many
=
True
)
EngineApi
.
track_schema
=
TrackServiceSchema
()
...
...
@@ -265,6 +277,8 @@ class CurrentTrackResource(Resource):
def
get
(
self
):
track
=
TrackService
.
select_current
()
if
not
track
:
return
abort
(
204
)
# No content available
return
EngineApi
.
track_schema
.
dump
(
track
)
...
...
@@ -278,6 +292,8 @@ class TracksByDayResource(Resource):
date
=
datetime
.
strptime
(
date_string
,
"
%Y-%m-%d
"
)
self
.
logger
.
debug
(
"
Query track-service by day: %s
"
%
str
(
date
))
tracks
=
TrackService
.
select_by_day
(
date
)
if
not
tracks
:
return
abort
(
204
)
# No content available
return
EngineApi
.
trackservice_schema
.
dump
(
tracks
)
...
...
@@ -291,6 +307,8 @@ class UpcomingSchedulesResource(Resource):
now
=
datetime
.
now
()
self
.
logger
.
debug
(
"
Query upcoming schedules after %s
"
%
str
(
now
))
schedules
=
Schedule
.
select_upcoming
(
3
)
if
not
schedules
:
return
abort
(
204
)
# No content available
return
EngineApi
.
schedule_schema
.
dump
(
schedules
)
...
...
@@ -310,6 +328,8 @@ class ReportResource(Resource):
self
.
logger
.
debug
(
"
Query report for month: %s - %s
"
%
(
str
(
first_day
),
str
(
next_month
)))
report
=
TrackService
.
select_by_range
(
first_day
,
next_month
)
if
not
report
:
return
abort
(
204
)
# No content available
return
EngineApi
.
report_schema
.
dump
(
report
)
...
...
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