-\r
-\r
-def registrations(uow: unit_of_work.AbstractUnitOfWork):\r
- with uow:\r
- li = uow.registrations.list()\r
- return [r.serialize() for r in li]\r
-\r
-\r
-def registration_one(registrationId: str,\r
- uow: unit_of_work.AbstractUnitOfWork):\r
- with uow:\r
- first = uow.registrations.get(registrationId)\r
- return first.serialize() if first is not None else None\r
-\r
-\r
-def registration_create(registrationDto: RegistrationDTO.registration,\r
- bus: messagebus.MessageBus):\r
-\r
- reg_uuid = str(uuid.uuid4())\r
- registration = Registration(\r
- reg_uuid, registrationDto['callback'])\r
- with bus.uow as uow:\r
- uow.registrations.add(registration)\r
- logging.debug('before event length {}'.format(\r
- len(registration.events)))\r
- registration.events.append(events.RegistrationChanged(\r
- reg_uuid,\r
- datetime.now()))\r
- logging.debug('after event length {}'.format(len(registration.events)))\r
- uow.commit()\r
- _handle_events(bus)\r
- return {"registrationId": reg_uuid}\r
-\r
-\r
-def registration_delete(registrationId: str,\r
- uow: unit_of_work.AbstractUnitOfWork):\r
- with uow:\r
- uow.registrations.delete(registrationId)\r
- uow.commit()\r
- return True\r
-\r
-\r
-def _handle_events(bus: messagebus.MessageBus):\r
- # handle events\r
- events = bus.uow.collect_new_events()\r
- for event in events:\r
- bus.handle(event)\r
- return True\r