def get_all(self) -> typing.List[AdminEntity]: with current_session() as session: admins = session.query(Admin).all() if admins: entities = [self.build_entity(admin) for admin in admins] else: entities = [] return entities
def get_all(self) -> typing.List[DriverEntity]: with current_session() as session: drivers = session.query(Driver).all() if drivers: entities = [self.build_entity(driver) for driver in drivers] else: entities = [] return entities
def get(self, id: int) -> typing.Optional[AdminEntity]: with current_session() as session: admin = session.query(Admin).get(id) if admin: entity = self.build_entity(admin) else: entity = None return entity
def get_by_status(self, status: DriverStatus) -> typing.List[DriverEntity]: with current_session() as session: drivers = session.query(Driver).filter( Driver.status == status).all() if drivers: entities = [self.build_entity(driver) for driver in drivers] else: entities = [] return entities
def get_by_tg_id(self, telegram_id: int) -> typing.Optional[DriverEntity]: with current_session() as session: driver = session.query(Driver).filter( Driver.telegram_id == telegram_id).first() if driver: entity = self.build_entity(driver) else: entity = None return entity
def get_by_tg_id(self, telegram_id: int) -> typing.Optional[AdminEntity]: with current_session() as session: admin = session.query(Admin).filter( Admin.telegram_id == telegram_id).first() if admin: entity = self.build_entity(admin) else: entity = None return entity
def craete(self, entity: DriverEntity) -> typing.Optional[DriverEntity]: orm_driver = self.build_orm_entity(entity) with current_session() as session: try: session.add(orm_driver) session.commit() except IntegrityError: entity = None else: entity = self.build_entity(orm_driver) return entity
def create(self, entity: AdminEntity) -> typing.Optional[AdminEntity]: orm_admin = self.build_orm_entity(entity) with current_session() as session: try: session.add(orm_admin) session.commit() except IntegrityError: entity = None else: entity = self.build_entity(orm_admin) return entity
def set_status(self, telegram_id: int, status: DriverStatus) -> None: with current_session() as session: driver = session.query(Driver).filter( Driver.telegram_id == telegram_id).update({'status': status}) session.commit()
def delete(self, telegram_id: int) -> bool: with current_session() as session: res = session.query(Driver).filter( Driver.telegram_id == telegram_id).delete() session.commit() return bool(res)