mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 14:14:22 +01:00
Adds get_summary to extended appointment
The Watcher used to create the summary, but that was not modular enough and introduced issues when testing
This commit is contained in:
@@ -6,6 +6,15 @@ class ExtendedAppointment(Appointment):
|
|||||||
super().__init__(locator, to_self_delay, encrypted_blob)
|
super().__init__(locator, to_self_delay, encrypted_blob)
|
||||||
self.user_id = user_id
|
self.user_id = user_id
|
||||||
|
|
||||||
|
def get_summary(self):
|
||||||
|
"""
|
||||||
|
Returns the summary of an appointment, consisting on the locator, the user_id and the appointment size.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
:obj:`dict`: the appointment summary.
|
||||||
|
"""
|
||||||
|
return {"locator": self.locator, "user_id": self.user_id, "size": len(self.encrypted_blob)}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, appointment_data):
|
def from_dict(cls, appointment_data):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -128,11 +128,12 @@ class Watcher:
|
|||||||
# The uuids are generated as the RIPMED160(locator||user_pubkey).
|
# The uuids are generated as the RIPMED160(locator||user_pubkey).
|
||||||
# If an appointment is requested by the user the uuid can be recomputed and queried straightaway (no maps).
|
# If an appointment is requested by the user the uuid can be recomputed and queried straightaway (no maps).
|
||||||
uuid = hash_160("{}{}".format(appointment.locator, user_id))
|
uuid = hash_160("{}{}".format(appointment.locator, user_id))
|
||||||
appointment_dict = {"locator": appointment.locator, "user_id": user_id, "size": len(appointment.encrypted_blob)}
|
|
||||||
|
|
||||||
available_slots = self.gatekeeper.update_available_slots(user_id, appointment_dict, self.appointments.get(uuid))
|
available_slots = self.gatekeeper.update_available_slots(
|
||||||
|
user_id, appointment.get_summary(), self.appointments.get(uuid)
|
||||||
|
)
|
||||||
self.gatekeeper.registered_users[user_id].appointments.append(uuid)
|
self.gatekeeper.registered_users[user_id].appointments.append(uuid)
|
||||||
self.appointments[uuid] = appointment_dict
|
self.appointments[uuid] = appointment.get_summary()
|
||||||
|
|
||||||
if appointment.locator in self.locator_uuid_map:
|
if appointment.locator in self.locator_uuid_map:
|
||||||
# If the uuid is already in the map it means this is an update.
|
# If the uuid is already in the map it means this is an update.
|
||||||
|
|||||||
Reference in New Issue
Block a user