Esempio n. 1
0
    def delete(self, ctx, object_id) -> None:
        session: Session = ctx.get(CTX_SQL_SESSION)

        transaction = session.query(SQLTransaction).filter(
            SQLTransaction.id == object_id).one()

        with track_modifications(ctx, session, transaction):
            session.delete(transaction)
        session.flush()
Esempio n. 2
0
    def delete(self, ctx, id) -> None:
        session: Session = ctx.get(CTX_SQL_SESSION)

        room = session.query(Chambre).filter(Chambre.id == id).one_or_none()
        if room is None:
            raise RoomNotFoundError(id)

        with track_modifications(ctx, session, room):
            session.delete(room)
Esempio n. 3
0
    def validate(self, ctx, id) -> None:
        session: Session = ctx.get(CTX_SQL_SESSION)

        query = session.query(SQLTransaction)
        query = query.filter(SQLTransaction.id == id)

        transaction = query.one()
        with track_modifications(ctx, session, transaction):
            transaction.pending_validation = False
        session.flush()
Esempio n. 4
0
    def update(self,
               ctx,
               abstract_device: AbstractDevice,
               override=False) -> Device:
        session: Session = ctx.get(CTX_SQL_SESSION)

        query = session.query(SQLDevice)
        query = query.filter(SQLDevice.id == abstract_device.id)

        device = query.one_or_none()
        with track_modifications(ctx, session, device):
            new_device = _merge_sql_with_entity(abstract_device, device,
                                                override)

        return _map_device_sql_to_entity(new_device)
Esempio n. 5
0
    def create(self, ctx, abstract_transaction: AbstractTransaction) -> object:
        session: Session = ctx.get(CTX_SQL_SESSION)

        now = datetime.now()

        admin_id = ctx.get(CTX_ADMIN)

        account_src = None
        if abstract_transaction.src is not None:
            account_src = session.query(Account).filter(
                Account.id == abstract_transaction.src).one_or_none()
            if not account_src:
                raise AccountNotFoundError(abstract_transaction.src)

        account_dst = None
        if abstract_transaction.dst is not None:
            account_dst = session.query(Account).filter(
                Account.id == abstract_transaction.dst).one_or_none()
            if not account_dst:
                raise AccountNotFoundError(abstract_transaction.dst)

        method = None
        if abstract_transaction.payment_method is not None:
            method = session.query(PaymentMethod).filter(
                PaymentMethod.id ==
                abstract_transaction.payment_method).one_or_none()
            if not method:
                raise PaymentMethodNotFoundError(
                    abstract_transaction.payment_method)

        transaction = SQLTransaction(
            src=account_src.id if account_src else None,
            dst=account_dst.id if account_dst else None,
            value=abstract_transaction.value,
            name=abstract_transaction.name,
            timestamp=now,
            attachments="",
            type=method.id if method else None,
            author_id=admin_id,
            pending_validation=abstract_transaction.pending_validation
            if abstract_transaction.pending_validation else False)

        with track_modifications(ctx, session, transaction):
            session.add(transaction)
        session.flush()

        return _map_transaction_sql_to_entity(transaction)
Esempio n. 6
0
    def update(self,
               ctx,
               abstract_member: AbstractMember,
               override=False) -> object:
        session: Session = ctx.get(CTX_SQL_SESSION)

        query = session.query(Adherent)\
            .filter(Adherent.id == abstract_member.id)

        adherent = query.one()

        with track_modifications(ctx, session, adherent):
            new_adherent = _merge_sql_with_entity(abstract_member, adherent,
                                                  override)
        session.flush()

        return _map_member_sql_to_entity(new_adherent)
Esempio n. 7
0
    def create(self, ctx, obj: DeviceBody) -> Device:
        session: Session = ctx.get(CTX_SQL_SESSION)
        now = datetime.now()

        device = SQLDevice(mac=obj.mac,
                           created_at=now,
                           updated_at=now,
                           last_seen=now,
                           type=DeviceType[obj.connection_type].value,
                           adherent_id=obj.member,
                           ip='En attente',
                           ipv6='En attente')

        with track_modifications(ctx, session, device):
            session.add(device)
        session.flush()

        return _map_device_sql_to_entity(device)
Esempio n. 8
0
    def create(self, ctx, object_to_create: Member) -> object:
        session: Session = ctx.get(CTX_SQL_SESSION)

        now = datetime.now()

        member: Adherent = Adherent(
            nom=object_to_create.last_name,
            prenom=object_to_create.first_name,
            mail=object_to_create.email,
            login=object_to_create.username,
            created_at=now,
            updated_at=now,
            commentaires=object_to_create.comment,
            date_de_depart=object_to_create.departure_date,
        )

        with track_modifications(ctx, session, member):
            session.add(member)
        session.flush()

        return _map_member_sql_to_entity(member)
Esempio n. 9
0
    def update(self, ctx, value_modifier=None, transaction=None):
        session: Session = ctx.get(CTX_SQL_SESSION)

        now = datetime.now()

        fond, coffre = self.get(ctx)

        fond += decimal.Decimal(value_modifier)

        cashbox_update = SQLCashbox(
            fond=fond,
            coffre=coffre,
            date=now,
            created_at=now,
            updated_at=now,
            linked_transaction=transaction.id if transaction is not None else None
        )

        with track_modifications(ctx, session, cashbox_update):
            session.add(cashbox_update)
        pass
Esempio n. 10
0
    def create(self, ctx, abstract_account: Account) -> object:
        session: Session = ctx.get(CTX_SQL_SESSION)
        LOG.debug("sql_account_repository_create_called", extra=log_extra(ctx, account_type=abstract_account.account_type))

        now = datetime.now()

        account_type_query = session.query(AccountType)
        if abstract_account.account_type is not None:
            LOG.debug("sql_account_repository_search_account_type", extra=log_extra(ctx, account_type=abstract_account.account_type))
            account_type_query = account_type_query.filter(AccountType.id == abstract_account.account_type)
        else:
            account_type_query = account_type_query.filter(AccountType.name == "Adherent")

        account_type = account_type_query.one_or_none()
        if account_type is None:
            raise AccountNotFoundError(abstract_account.account_type)

        adherent = None
        if abstract_account.member is not None:
            adherent = session.query(Adherent).filter(Adherent.id == abstract_account.member).one_or_none()
            if not adherent:
                raise MemberNotFoundError(abstract_account.member)

        account = SQLAccount(
            name=abstract_account.name,
            actif=abstract_account.actif,
            type=account_type.id,
            creation_date=now,
            compte_courant=abstract_account.compte_courant,
            pinned=abstract_account.pinned,
            adherent_id=adherent.id if adherent else None
        )

        with track_modifications(ctx, session, account):
            session.add(account)
        session.flush()
        LOG.debug("sql_account_repository_create_finished", extra=log_extra(ctx, account_id=account.id))

        return _map_account_sql_to_entity(account)
Esempio n. 11
0
    def create(self, ctx, abstract_room: Room) -> Room:
        session: Session = ctx.get(CTX_SQL_SESSION)
        now = datetime.now()

        vlan = None
        if abstract_room.vlan is not None:
            vlan = session.query(Vlan).filter(
                Vlan.numero == abstract_room.vlan).one_or_none()
            if not vlan:
                raise VLANNotFoundError(str(abstract_room.vlan))

        room = Chambre(
            numero=abstract_room.room_number,
            description=abstract_room.description,
            created_at=now,
            updated_at=now,
            vlan_id=vlan.id if vlan else None,
        )

        with track_modifications(ctx, session, room):
            session.add(room)
        session.flush()

        return _map_room_sql_to_entity(room)
Esempio n. 12
0
 def update_password(self, ctx, member_id, hashed_password):
     session: Session = ctx.get(CTX_SQL_SESSION)
     adherent = session.query(Adherent).filter(
         Adherent.id == member_id).one_or_none()
     with track_modifications(ctx, session, adherent):
         adherent.password = hashed_password
Esempio n. 13
0
 def delete(self, ctx, member_id) -> None:
     session: Session = ctx.get(CTX_SQL_SESSION)
     member = session.query(Adherent).filter(
         Adherent.id == member_id).one_or_none()
     with track_modifications(ctx, session, member):
         session.delete(member)
Esempio n. 14
0
 def delete(self, ctx, id) -> None:
     session: Session = ctx.get(CTX_SQL_SESSION)
     device = session.query(SQLDevice).filter(
         SQLDevice.id == id).one_or_none()
     with track_modifications(ctx, session, device):
         session.delete(device)