Exemple #1
0
 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
Exemple #2
0
 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
Exemple #3
0
 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
Exemple #4
0
 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
Exemple #5
0
 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
Exemple #6
0
 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
Exemple #7
0
 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
Exemple #8
0
 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
Exemple #9
0
 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()
Exemple #10
0
 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)