Skip to content
Snippets Groups Projects
Commit 5c642669 authored by David Trattnig's avatar David Trattnig
Browse files

Wiring service via app context.

parent 16157ce8
No related branches found
No related tags found
No related merge requests found
...@@ -49,8 +49,8 @@ def build_app(app): ...@@ -49,8 +49,8 @@ def build_app(app):
ma.init_app(app) ma.init_app(app)
return app return app
api = connexion.App(__name__, specification_dir='rest/swagger') api = connexion.App(__name__, specification_dir='rest/swagger', arguments={'title': 'AURA Engine API'})
api.add_api('swagger.yaml', arguments={'title': 'AURA Engine API'}, pythonic_params=True) api.add_api('swagger.yaml', pythonic_params=True)
app = build_app(api.app) app = build_app(api.app)
...@@ -68,7 +68,8 @@ with app.app_context(): ...@@ -68,7 +68,8 @@ with app.app_context():
""" """
db.create_all() db.create_all()
service = ApiService(config, logger) service = ApiService(config, logger)
logger.info("API server initialized.") app.config['SERVICE'] = service
logger.info("Engine API server initialized.")
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -7,6 +7,8 @@ from src.rest.models.play_log_entry import PlayLogEntry # noqa: E501 ...@@ -7,6 +7,8 @@ from src.rest.models.play_log_entry import PlayLogEntry # noqa: E501
from src.rest.models.status_entry import StatusEntry # noqa: E501 from src.rest.models.status_entry import StatusEntry # noqa: E501
from src.rest import util from src.rest import util
from flask import current_app
def activate_engine(engine_number): # noqa: E501 def activate_engine(engine_number): # noqa: E501
"""Set active engine """Set active engine
...@@ -18,6 +20,7 @@ def activate_engine(engine_number): # noqa: E501 ...@@ -18,6 +20,7 @@ def activate_engine(engine_number): # noqa: E501
:rtype: None :rtype: None
""" """
service = current_app.config['SERVICE']
return 'do some magic!' return 'do some magic!'
...@@ -29,6 +32,7 @@ def clock_info(): # noqa: E501 ...@@ -29,6 +32,7 @@ def clock_info(): # noqa: E501
:rtype: ClockInfo :rtype: ClockInfo
""" """
service = current_app.config['SERVICE']
return 'do some magic!' return 'do some magic!'
...@@ -40,6 +44,7 @@ def get_active_engine(): # noqa: E501 ...@@ -40,6 +44,7 @@ def get_active_engine(): # noqa: E501
:rtype: StatusEntry :rtype: StatusEntry
""" """
service = current_app.config['SERVICE']
return 'do some magic!' return 'do some magic!'
...@@ -53,6 +58,7 @@ def get_engine_health(engine_number): # noqa: E501 ...@@ -53,6 +58,7 @@ def get_engine_health(engine_number): # noqa: E501
:rtype: HealthInfo :rtype: HealthInfo
""" """
service = current_app.config['SERVICE']
return 'do some magic!' return 'do some magic!'
...@@ -66,6 +72,7 @@ def get_report(year_month): # noqa: E501 ...@@ -66,6 +72,7 @@ def get_report(year_month): # noqa: E501
:rtype: List[PlayLogEntry] :rtype: List[PlayLogEntry]
""" """
service = current_app.config['SERVICE']
return 'do some magic!' return 'do some magic!'
...@@ -79,4 +86,5 @@ def log_engine_health(engine_number): # noqa: E501 ...@@ -79,4 +86,5 @@ def log_engine_health(engine_number): # noqa: E501
:rtype: None :rtype: None
""" """
service = current_app.config['SERVICE']
return 'do some magic!' return 'do some magic!'
...@@ -6,6 +6,8 @@ import six ...@@ -6,6 +6,8 @@ import six
from src.rest.models.play_log_entry import PlayLogEntry # noqa: E501 from src.rest.models.play_log_entry import PlayLogEntry # noqa: E501
from src.rest import util from src.rest import util
from flask import current_app
def current_track(): # noqa: E501 def current_track(): # noqa: E501
"""Get current track """Get current track
...@@ -15,7 +17,7 @@ def current_track(): # noqa: E501 ...@@ -15,7 +17,7 @@ def current_track(): # noqa: E501
:rtype: PlayLogEntry :rtype: PlayLogEntry
""" """
from src.app import service service = current_app.config['SERVICE']
return service.current_track() return service.current_track()
...@@ -31,5 +33,5 @@ def list_tracks(offset=None, limit=None): # noqa: E501 ...@@ -31,5 +33,5 @@ def list_tracks(offset=None, limit=None): # noqa: E501
:rtype: List[PlayLogEntry] :rtype: List[PlayLogEntry]
""" """
from src.app import service service = current_app.config['SERVICE']
return service.list_tracks(offset, limit) return service.list_tracks(offset, limit)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment