From a85ebf0a8bd16ff887a3306692f874517d6d0947 Mon Sep 17 00:00:00 2001 From: "jordi.nadeu" Date: Mon, 16 Dec 2019 19:17:30 +0100 Subject: [PATCH] add new attributes in Lot and User models --- ereuse_devicehub/resources/lot/models.py | 7 ++++++- ereuse_devicehub/resources/lot/models.pyi | 4 +++- ereuse_devicehub/resources/lot/schemas.py | 4 ++-- ereuse_devicehub/resources/user/models.py | 1 + ereuse_devicehub/resources/user/models.pyi | 1 + ereuse_devicehub/resources/user/schemas.py | 1 + 6 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ereuse_devicehub/resources/lot/models.py b/ereuse_devicehub/resources/lot/models.py index 39fd1804..e7afd49d 100644 --- a/ereuse_devicehub/resources/lot/models.py +++ b/ereuse_devicehub/resources/lot/models.py @@ -71,7 +71,12 @@ class Lot(Thing): author = db.relationship(User, primaryjoin=author_id == User.id) transfer_state = db.Column(IntEnum(TransferState), default=TransferState.Initial, nullable=False) transfer_state.comment = TransferState.__doc__ - receiver = db.Column(CIText(), default='', nullable=False) + receiver_id = db.Column(UUID(as_uuid=False), + db.ForeignKey(User.ethereum_address), + nullable=True, + default=lambda: g.user.ethereum_address) + receiver = db.relationship(User, primaryjoin=receiver_id == User.ethereum_address) + delivery_note_address = db.Column(CIText(), nullable=True) def __init__(self, name: str, closed: bool = closed.default.arg, description: str = None) -> None: diff --git a/ereuse_devicehub/resources/lot/models.pyi b/ereuse_devicehub/resources/lot/models.pyi index e084a3fa..c320fd07 100644 --- a/ereuse_devicehub/resources/lot/models.pyi +++ b/ereuse_devicehub/resources/lot/models.pyi @@ -27,7 +27,9 @@ class Lot(Thing): deposit = ... # type: Column author_id = ... # type: Column transfer_state = ... # type: Column - receiver = ... # type: Column + receiver_id = ... # type: Column + receiver = ... # type: relationship + delivery_note_address = ... # type: Column def __init__(self, name: str, closed: bool = closed.default.arg) -> None: super().__init__() diff --git a/ereuse_devicehub/resources/lot/schemas.py b/ereuse_devicehub/resources/lot/schemas.py index b9789021..6155313e 100644 --- a/ereuse_devicehub/resources/lot/schemas.py +++ b/ereuse_devicehub/resources/lot/schemas.py @@ -23,5 +23,5 @@ class Lot(Thing): description=m.Lot.deposit.__doc__) # author_id = NestedOn(s_user.User,only_query='author_id') author_id = f.UUID(dump_only=True) - tranfer_state = EnumField(TransferState, description=m.Lot.transfer_state.comment) - receiver = SanitizedStr(validate=f.validate.Length(max=42)) \ No newline at end of file + transfer_state = EnumField(TransferState, description=m.Lot.transfer_state.comment) + receiver_id = SanitizedStr(validate=f.validate.Length(max=42)) \ No newline at end of file diff --git a/ereuse_devicehub/resources/user/models.py b/ereuse_devicehub/resources/user/models.py index 1dd2cad7..a254aaf0 100644 --- a/ereuse_devicehub/resources/user/models.py +++ b/ereuse_devicehub/resources/user/models.py @@ -24,6 +24,7 @@ class User(Thing): backref=db.backref('users', lazy=True, collection_class=set), secondary=lambda: UserInventory.__table__, collection_class=set) + ethereum_address = Column(UUID(as_uuid=False), unique=True) # todo set restriction that user has, at least, one active db diff --git a/ereuse_devicehub/resources/user/models.pyi b/ereuse_devicehub/resources/user/models.pyi index 6e8d03b9..1cacb052 100644 --- a/ereuse_devicehub/resources/user/models.pyi +++ b/ereuse_devicehub/resources/user/models.pyi @@ -17,6 +17,7 @@ class User(Thing): password = ... # type: Column token = ... # type: Column inventories = ... # type: relationship + ethereum_address = ... # type: Column def __init__(self, email: str, password: str = None, inventories: Set[Inventory] = None) -> None: diff --git a/ereuse_devicehub/resources/user/schemas.py b/ereuse_devicehub/resources/user/schemas.py index e8d0d768..00d022ad 100644 --- a/ereuse_devicehub/resources/user/schemas.py +++ b/ereuse_devicehub/resources/user/schemas.py @@ -19,6 +19,7 @@ class User(Thing): description='Use this token in an Authorization header to access the app.' 'The token can change overtime.') inventories = NestedOn(Inventory, many=True, dump_only=True) + ethereum_address = String(description='User identifier address inside the Blockchain') def __init__(self, only=None,