diff --git a/src/rest/controllers/internal_controller.py b/src/rest/controllers/internal_controller.py index bdd5d1e92c6ca9b7fd330cb3bd92faea481173fd..dd4d30e07ce478978dfd4d374fb0e17f5c3cb053 100644 --- a/src/rest/controllers/internal_controller.py +++ b/src/rest/controllers/internal_controller.py @@ -24,7 +24,7 @@ def add_playlog(body): # noqa: E501 if connexion.request.is_json: body = PlayLog.from_dict(connexion.request.get_json()) # noqa: E501 service = current_app.config['SERVICE'] - return service.store_playlog(body) + return service.store_playlog(body, connexion.request.get_json()) def clock_info(): # noqa: E501 diff --git a/src/service.py b/src/service.py index 234809eb9758123a57ed32ed7dc7a08096dc8ccb..f99d0dcee3354bc2bdfcdf08c208e39b7deda527 100644 --- a/src/service.py +++ b/src/service.py @@ -140,7 +140,7 @@ class ApiService(): return tracklist_schema.dump(tracklist) - def store_playlog(self, data): + def store_playlog(self, data, plain_json): """ Stores the passed playlog entry. @@ -161,19 +161,15 @@ class ApiService(): try: playlog = PlayLog(data) playlog.save() - playlog = PlayLog.get(data.track_start) - self.logger.debug("Stored playlog for '%s'" % playlog.track_start) + self.logger.debug("Stored playlog for '%s'" % data.track_start) except sqlalchemy.exc.IntegrityError as e: - self.logger.info("Playlog for '%s' is already existing in local database. Skipping..." % playlog.track_start) + self.logger.info("Playlog for '%s' is already existing in local database. Skipping..." % data.track_start) # Main Node: Push to Sync Node, if enabled if self.node_type == NodeType.MAIN and self.sync_host and self.api_playlog: - playlog_schema = PlayLogSchema() - json_playlog = playlog_schema.dump(playlog) - try: api_url = self.sync_host + self.api_playlog - r = requests.post(api_url, json=json_playlog) + r = requests.post(api_url, json=plain_json) if r.status_code == 204: self.logger.info("Successfully pushed playlog for '%s' to '%s'" % (playlog.track_start, self.sync_host)) playlog.is_synced = True @@ -195,17 +191,17 @@ class ApiService(): return clockinfo_schema.dump(info) - def set_clock_info(self, body, plain_json): + def set_clock_info(self, data, plain_json): """ Sets the clock info for the given source (engine1, engine2, other). Args: source_number (Integer): Number of the engine """ - if body.engine_source <= 0: + if data.engine_source <= 0: return - clock_info = ClockInfo(body.engine_source, body.current_playlist, body.current_schedule, body.next_schedule) + clock_info = ClockInfo(data.engine_source, data.current_playlist, data.current_schedule, data.next_schedule) clock_info.merge() if self.config.get("enable_federation") == "false":