diff --git a/src/rest/controllers/internal_controller.py b/src/rest/controllers/internal_controller.py index c00073965596f927be6afadb63130b1b657410dc..7dcd6954ca59e3d8620db16c7256cd90da143319 100644 --- a/src/rest/controllers/internal_controller.py +++ b/src/rest/controllers/internal_controller.py @@ -3,6 +3,7 @@ import six from src.rest.models.clock_info import ClockInfo # noqa: E501 from src.rest.models.health_info import HealthInfo # noqa: E501 +from src.rest.models.inline_response400 import InlineResponse400 # noqa: E501 from src.rest.models.play_log_entry import PlayLogEntry # noqa: E501 from src.rest.models.status_entry import StatusEntry # noqa: E501 from src.rest import util @@ -10,7 +11,6 @@ from src.rest import util from flask import current_app from dateutil.parser import parse - def activate_engine(engine_number): # noqa: E501 """Set active engine @@ -21,19 +21,23 @@ def activate_engine(engine_number): # noqa: E501 :rtype: None """ - service = current_app.config['SERVICE'] + return 'do some magic!' -def add_playlog(): # noqa: E501 +def add_playlog(body): # noqa: E501 """Adds an entry to the playlog Stores the passed playlog entry # noqa: E501 + :param body: + :type body: dict | bytes - :rtype: PlayLogEntry + :rtype: None """ + if connexion.request.is_json: + body = PlayLogEntry.from_dict(connexion.request.get_json()) # noqa: E501 service = current_app.config['SERVICE'] - service.store_playlog() + service.store_playlog(body) def clock_info(): # noqa: E501 @@ -44,7 +48,6 @@ def clock_info(): # noqa: E501 :rtype: ClockInfo """ - service = current_app.config['SERVICE'] return 'do some magic!' @@ -56,7 +59,6 @@ def get_active_engine(): # noqa: E501 :rtype: StatusEntry """ - service = current_app.config['SERVICE'] return 'do some magic!' @@ -70,7 +72,6 @@ def get_engine_health(engine_number): # noqa: E501 :rtype: HealthInfo """ - service = current_app.config['SERVICE'] return 'do some magic!' @@ -84,7 +85,6 @@ def get_report(year_month): # noqa: E501 :rtype: List[PlayLogEntry] """ - service = current_app.config['SERVICE'] return 'do some magic!' @@ -94,7 +94,7 @@ def list_playlog(date_time, page=None, limit=None): # noqa: E501 Get paginated playlog entries for since the given timestamp. # noqa: E501 :param date_time: Get entries after this timestamp (e.g. '2020-08-29T09:12:33.001Z') - :type date_time: dict | bytes + :type date_time: str :param page: The number of items to skip before starting to collect the result set :type page: int :param limit: The numbers of items to return per page @@ -117,5 +117,4 @@ def log_engine_health(engine_number): # noqa: E501 :rtype: None """ - service = current_app.config['SERVICE'] return 'do some magic!' diff --git a/src/rest/models/__init__.py b/src/rest/models/__init__.py index 379af5f5ead8d928e88a98db4519011efd56b764..dde7e802354b1214938da8212a1694aa2b4413b7 100644 --- a/src/rest/models/__init__.py +++ b/src/rest/models/__init__.py @@ -5,7 +5,8 @@ from __future__ import absolute_import # import models into model package from src.rest.models.clock_info import ClockInfo from src.rest.models.health_info import HealthInfo +from src.rest.models.inline_response400 import InlineResponse400 from src.rest.models.play_log_entry import PlayLogEntry from src.rest.models.playlist_entry import PlaylistEntry -from src.rest.models.timeslot import Timeslot from src.rest.models.status_entry import StatusEntry +from src.rest.models.timeslot import Timeslot diff --git a/src/rest/models/clock_info.py b/src/rest/models/clock_info.py index 88d3c83615db3a9cf486f3aba50facf9a84547c6..5475019f1554a546a852f80a8e07113e9d269249 100644 --- a/src/rest/models/clock_info.py +++ b/src/rest/models/clock_info.py @@ -91,6 +91,8 @@ class ClockInfo(Model): :param current_timeslot: The current_timeslot of this ClockInfo. :type current_timeslot: Timeslot """ + if current_timeslot is None: + raise ValueError("Invalid value for `current_timeslot`, must not be `None`") # noqa: E501 self._current_timeslot = current_timeslot diff --git a/src/rest/models/inline_response400.py b/src/rest/models/inline_response400.py new file mode 100644 index 0000000000000000000000000000000000000000..8428ccdffd6b1af60bfb7958dc46eb1683bbe7cb --- /dev/null +++ b/src/rest/models/inline_response400.py @@ -0,0 +1,62 @@ +# coding: utf-8 + +from __future__ import absolute_import +from datetime import date, datetime # noqa: F401 + +from typing import List, Dict # noqa: F401 + +from src.rest.models.base_model_ import Model +from src.rest import util + + +class InlineResponse400(Model): + """NOTE: This class is auto generated by the swagger code generator program. + + Do not edit the class manually. + """ + def __init__(self, message=None): # noqa: E501 + """InlineResponse400 - a model defined in Swagger + + :param message: The message of this InlineResponse400. # noqa: E501 + :type message: str + """ + self.swagger_types = { + 'message': str + } + + self.attribute_map = { + 'message': 'message' + } + self._message = message + + @classmethod + def from_dict(cls, dikt): + """Returns the dict as a model + + :param dikt: A dict. + :type: dict + :return: The inline_response_400 of this InlineResponse400. # noqa: E501 + :rtype: InlineResponse400 + """ + return util.deserialize_model(dikt, cls) + + @property + def message(self): + """Gets the message of this InlineResponse400. + + + :return: The message of this InlineResponse400. + :rtype: str + """ + return self._message + + @message.setter + def message(self, message): + """Sets the message of this InlineResponse400. + + + :param message: The message of this InlineResponse400. + :type message: str + """ + + self._message = message diff --git a/src/rest/models/play_log_entry.py b/src/rest/models/play_log_entry.py index 79d0e7e71839debac0cac0627351044c8039cb3f..5cf3831fa73857b7365ab5740b93590360686286 100644 --- a/src/rest/models/play_log_entry.py +++ b/src/rest/models/play_log_entry.py @@ -14,7 +14,7 @@ class PlayLogEntry(Model): Do not edit the class manually. """ - def __init__(self, track_start=None, track_artist=None, track_album=None, track_title=None, track_duration=None, track_type=None, timeslot_id=None, show_name=None): # noqa: E501 + def __init__(self, track_start=None, track_artist=None, track_album=None, track_title=None, track_duration=None, track_type=None, timeslot_id=None, show_name=None, log_source=None): # noqa: E501 """PlayLogEntry - a model defined in Swagger :param track_start: The track_start of this PlayLogEntry. # noqa: E501 @@ -33,6 +33,8 @@ class PlayLogEntry(Model): :type timeslot_id: int :param show_name: The show_name of this PlayLogEntry. # noqa: E501 :type show_name: str + :param log_source: The log_source of this PlayLogEntry. # noqa: E501 + :type log_source: int """ self.swagger_types = { 'track_start': datetime, @@ -42,7 +44,8 @@ class PlayLogEntry(Model): 'track_duration': int, 'track_type': int, 'timeslot_id': int, - 'show_name': str + 'show_name': str, + 'log_source': int } self.attribute_map = { @@ -53,7 +56,8 @@ class PlayLogEntry(Model): 'track_duration': 'track_duration', 'track_type': 'track_type', 'timeslot_id': 'timeslot_id', - 'show_name': 'show_name' + 'show_name': 'show_name', + 'log_source': 'log_source' } self._track_start = track_start self._track_artist = track_artist @@ -63,6 +67,7 @@ class PlayLogEntry(Model): self._track_type = track_type self._timeslot_id = timeslot_id self._show_name = show_name + self._log_source = log_source @classmethod def from_dict(cls, dikt): @@ -244,3 +249,24 @@ class PlayLogEntry(Model): """ self._show_name = show_name + + @property + def log_source(self): + """Gets the log_source of this PlayLogEntry. + + + :return: The log_source of this PlayLogEntry. + :rtype: int + """ + return self._log_source + + @log_source.setter + def log_source(self, log_source): + """Sets the log_source of this PlayLogEntry. + + + :param log_source: The log_source of this PlayLogEntry. + :type log_source: int + """ + + self._log_source = log_source diff --git a/src/rest/swagger/swagger.yaml b/src/rest/swagger/swagger.yaml index 656651d656f268bb2dbba402515640a732d8d4e2..ce882bf1e81856252aa7645127545270d139ee7d 100644 --- a/src/rest/swagger/swagger.yaml +++ b/src/rest/swagger/swagger.yaml @@ -113,7 +113,7 @@ paths: "400": description: bad input parameter x-openapi-router-controller: src.rest.controllers.internal_controller - /playlog/add: + /playlog/store: post: tags: - internal @@ -121,15 +121,21 @@ paths: description: | Stores the passed playlog entry operationId: add_playlog + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/PlayLogEntry' + required: true responses: "200": - description: Stored playlog + description: Successfully created a new playlog + "400": + description: Invalid request content: application/json: schema: - $ref: '#/components/schemas/PlayLogEntry' - "400": - description: bad input parameter + $ref: '#/components/schemas/inline_response_400' x-openapi-router-controller: src.rest.controllers.internal_controller /playlog/since/{date_time}: get: @@ -339,11 +345,15 @@ components: show_name: type: string example: Electronic Music from Brazil + log_source: + type: integer + example: 1 example: track_album: Bricolage track_start: 2020-08-29T09:12:33.001Z track_title: Chomp Samba show_name: Electronic Music from Brazil + log_source: 1 track_artist: Amon Tobin timeslot_id: 1 track_duration: 303 @@ -432,6 +442,7 @@ components: track_start: 2020-08-29T09:12:33.001Z track_title: Chomp Samba show_name: Electronic Music from Brazil + log_source: 1 track_artist: Amon Tobin timeslot_id: 1 track_duration: 303 @@ -516,4 +527,9 @@ components: album: XXYYXX title: Alone type: 1 + inline_response_400: + type: object + properties: + message: + type: string diff --git a/src/rest/test/test_internal_controller.py b/src/rest/test/test_internal_controller.py index b90612dfde77a514a6640eef3bdc0100de2f2515..4f18483a99a18a9b823700974f74011d44d03949 100644 --- a/src/rest/test/test_internal_controller.py +++ b/src/rest/test/test_internal_controller.py @@ -49,9 +49,12 @@ class TestInternalController(BaseTestCase): Adds an entry to the playlog """ + body = PlayLogEntry() response = self.client.open( - '/api/v1/playlog/add', - method='POST') + '/playlog/store', + method='POST', + data=json.dumps(body), + content_type='application/json') self.assert200(response, 'Response body is : ' + response.data.decode('utf-8'))