From e78d62602b104729757e1d37ccedba2f0767ce2f Mon Sep 17 00:00:00 2001 From: yiorgos marinellis Date: Mon, 23 Mar 2020 18:49:22 +0100 Subject: [PATCH] Align ProofTransfer to Chapter 6 on specs, fixes #12 --- ereuse_devicehub/resources/proof/models.py | 17 ++++++++++------- ereuse_devicehub/resources/proof/schemas.py | 10 ++++++---- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/ereuse_devicehub/resources/proof/models.py b/ereuse_devicehub/resources/proof/models.py index ff7a252e..6f63404b 100644 --- a/ereuse_devicehub/resources/proof/models.py +++ b/ereuse_devicehub/resources/proof/models.py @@ -85,13 +85,16 @@ class Proof(Thing): class ProofTransfer(JoinedTableMixin, Proof): - transfer_id = Column(UUID(as_uuid=True), ForeignKey(Trade.id), nullable=False) - transfer = relationship(DisposeProduct, - backref=backref("proof_transfer", - lazy=True, - uselist=False, - cascade=CASCADE_OWN), - primaryjoin=DisposeProduct.id == transfer_id) + supplier_id = db.Column(CIText(), + db.ForeignKey(User.ethereum_address), + nullable=False, + default=lambda: g.user.ethereum_address) + supplier = db.relationship(User, primaryjoin=lambda: ProofTransfer.supplier_id == User.ethereum_address) + receiver_id = db.Column(CIText(), + db.ForeignKey(User.ethereum_address), + nullable=False) + receiver = db.relationship(User, primaryjoin=lambda: ProofTransfer.receiver_id == User.ethereum_address) + deposit = Column(db.Integer, default=0) class ProofDataWipe(JoinedTableMixin, Proof): diff --git a/ereuse_devicehub/resources/proof/schemas.py b/ereuse_devicehub/resources/proof/schemas.py index 3070448e..9726381a 100644 --- a/ereuse_devicehub/resources/proof/schemas.py +++ b/ereuse_devicehub/resources/proof/schemas.py @@ -1,5 +1,5 @@ from flask import current_app as app -from marshmallow import Schema as MarshmallowSchema, ValidationError, validates_schema +from marshmallow import Schema as MarshmallowSchema, ValidationError, fields as f, validates_schema from marshmallow.fields import Boolean, DateTime, Integer, Nested, String, UUID from marshmallow.validate import Length from sqlalchemy.util import OrderedSet @@ -26,9 +26,11 @@ class Proof(Thing): class ProofTransfer(Proof): __doc__ = m.ProofTransfer.__doc__ - transfer = NestedOn(s_action.DisposeProduct, - required=True, - only_query='id') + deposit = Integer() + supplier_id = SanitizedStr(validate=f.validate.Length(max=STR_SIZE), + load_only=True, required=True, data_key='supplierID') + receiver_id = SanitizedStr(validate=f.validate.Length(max=STR_SIZE), + load_only=True, required=True, data_key='receiverID') class ProofDataWipe(Proof):