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

refact(api): set and get new upcoming timeslots

hold multiple, upcoming timeslots for clock. #26
parent 9b92e9f8
No related branches found
No related tags found
No related merge requests found
Pipeline #2265 passed
......@@ -419,7 +419,7 @@ class ClockInfo(db.Model):
current_timeslot = Column(
String(2048)
) # Stringified "#/components/schemas/Timeslot" OpenAPI JSON object
next_timeslot = Column(
upcoming_timeslots = Column(
String(2048)
) # Stringified "#/components/schemas/Timeslot" OpenAPI JSON object
......@@ -428,9 +428,9 @@ class ClockInfo(db.Model):
Initializes an clock info entry.
"""
def set_info(self, source_number, planned_playlist, current_timeslot, next_timeslot):
def set_info(self, source_number, planned_playlist, current_timeslot, upcoming_timeslots):
"""
Sets the values for a clock info entry.
Set the values for a clock info entry.
"""
self.log_time = datetime.datetime.now()
self.log_source = source_number
......@@ -442,10 +442,13 @@ class ClockInfo(db.Model):
self.current_timeslot = json.dumps(current_timeslot.to_dict(), default=str)
else:
self.current_timeslot = None
if next_timeslot:
self.next_timeslot = json.dumps(next_timeslot.to_dict(), default=str)
if upcoming_timeslots:
upcoming_list = []
for upcoming in upcoming_timeslots:
upcoming_list.append(upcoming.to_dict())
self.upcoming_timeslots = json.dumps(upcoming_list, default=str)
else:
self.next_timeslot = None
self.upcoming_timeslots = None
@staticmethod
def get(source_number):
......@@ -505,10 +508,10 @@ class ClockInfo(db.Model):
info["current_timeslot"]["timeslot_start"] = playlogs[0].track_start
# Get the next timeslot
if data.next_timeslot:
info["next_timeslot"] = json.loads(data.next_timeslot)
if data.upcoming_timeslots:
info["upcoming_timeslots"] = json.loads(data.upcoming_timeslots)
else:
info["next_timeslot"] = {}
info["upcoming_timeslots"] = {}
return info
......@@ -536,5 +539,5 @@ class ClockInfoSchema(ma.SQLAlchemySchema):
"planned_playlist",
"current_playlogs",
"current_timeslot",
"next_timeslot",
"upcoming_timeslots",
)
......@@ -238,7 +238,7 @@ class ApiService:
data.engine_source,
data.planned_playlist,
data.current_timeslot,
data.next_timeslot,
data.upcoming_timeslots,
)
if is_existing:
......
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