making main less complex

This commit is contained in:
2024-06-19 22:53:43 +02:00
parent bb5364d021
commit a54b19b938
4 changed files with 63 additions and 47 deletions

View File

@@ -0,0 +1,47 @@
from datetime import date, datetime
from model.DataStore import DataStore
from model.TimeSlot import TimeSlot
class TimeSlotContainer:
def __init__(self, ds: DataStore):
self._ds = ds
def get_open_time_slots(self) -> list[TimeSlot]:
return [ts for ts in self._ds.get_all_time_slots() if ts.end is None]
def get_all_time_slots(self) -> list[TimeSlot]:
return self._ds.get_all_time_slots()
def get_time_slots_by_date(self, d: date = datetime.now().date()):
return [ts for ts in self._ds.get_all_time_slots()
if ts.start.date() == datetime.now().date()]
def open_time_slot(self, name: str, start_dt: datetime = datetime.now()):
if len(self.get_open_time_slots()) > 0:
raise Exception("Ein event ist bereits aktiv.")
ts = TimeSlot(name)
ts.start = start_dt
self._ds.add_time_slot(ts)
self._ds.write_update()
def close_time_slot(self, end_dt: datetime = datetime.now()):
ts = self.get_open_time_slots()[0]
self._ds.remove_time_slot(ts)
ts.end = end_dt
self._ds.add_time_slot(ts)
self._ds.write_update()
def add_time_slot(self, name: str, start_dt: datetime, end_dt: datetime):
self.open_time_slot(name, start_dt)
self.close_time_slot(end_dt)
def update_time_slot(self, old: TimeSlot, new: TimeSlot):
raise NotImplementedError
def delete_time_slot(self, ts: TimeSlot):
raise NotImplementedError
time_slot_container = TimeSlotContainer(DataStore("data.json"))