Improves add_appointment method. Has some pending fixmes

- Start and end time have to be dealt with (changes required on the tower side)
- Sends appointments to every register tower. We may want to manage this better
This commit is contained in:
Sergi Delgado Segura
2020-04-09 17:58:09 +02:00
parent 08701f0fee
commit 6b025a2d9c
2 changed files with 59 additions and 10 deletions

View File

@@ -1,19 +1,23 @@
class TowerInfo:
def __init__(self, endpoint, available_slots):
def __init__(self, endpoint, available_slots, appointments=None):
self.endpoint = endpoint
self.available_slots = available_slots
if not appointments:
self.appointments = {}
else:
self.appointments = appointments
@classmethod
def from_dict(cls, tower_data):
endpoint = tower_data.get("endpoint")
available_slots = tower_data.get("available_slots")
appointments = tower_data.get("appointments")
if any(v is None for v in [endpoint, available_slots]):
if any(v is None for v in [endpoint, available_slots, appointments]):
raise ValueError("Wrong appointment data, some fields are missing")
if available_slots is None:
raise ValueError("Wrong tower data, some fields are missing")
return cls(endpoint, available_slots)
return cls(endpoint, available_slots, appointments)
def to_dict(self):
return self.__dict__