class UserCartSchema(ma.SQLAlchemyAutoSchema): user = ma.Nested("UserSchema", exclude=("addresses", "cards", "cart", "product_rating")) items = ma.List(ma.Nested("CartItemSchema")) class Meta: model = UserCart
class OrderSchema(ma.SQLAlchemyAutoSchema): user = ma.Nested("UserSchema", exclude=("addresses", "cards", "cart", "product_rating")) items = ma.List(ma.Nested("OrderedProductSchema")) total_price = ma.Float() class Meta: model = Order
class UserCartSchema(ma.SQLAlchemyAutoSchema): user = ma.Nested("UserSchema", exclude=("addresses", "cards", "password", "cart", "product_rating", "admin", "enabled_2fa", "email_verified", "email", "username", "active", "id")) items = ma.List(ma.Nested("CartItemSchema")) class Meta: model = UserCart
class UserSchema(ma.SQLAlchemyAutoSchema): addresses = ma.List(ma.Nested("AddressSchema", exclude=("user", ))) cards = ma.List(ma.Nested("CardSchema", exclude=("user", ))) forget_tokens = ma.List( ma.Nested("ResetPasswordTokenSchema", exclude=("user", ))) cart = ma.Nested("UserCartSchema", exclude=("user", )) product_rating = ma.List( ma.Nested("ProductRatingSchema", exclude=("user", "product"))) class Meta: model = User
class OrderSchema(ma.SQLAlchemyAutoSchema): user = ma.Nested("UserSchema", exclude=("addresses", "cards", "password", "cart", "product_rating", "admin", "enabled_2fa", "email_verified", "email", "username", "active", "id")) items = ma.List(ma.Nested("OrderedProductSchema"), dump_only=True) total_price = ma.Float(dump_only=True) tracking_no = fields.Str() address_id = fields.Integer() credit_card_id = fields.Integer() class Meta: model = Order
class AddressSchema(ma.SQLAlchemyAutoSchema): user = ma.Nested("UserSchema", exclude=("addresses", "cards", "password", "cart", "product_rating")) class Meta: model = Address
class CartItemSchema(ma.SQLAlchemyAutoSchema): product = ma.Nested("ProductSchema", exclude=("description", "pic_filename")) product_id = fields.Integer(required=True) quantity = fields.Integer(required=True) class Meta: model = CartItem
class ProductRatingSchema(ma.SQLAlchemyAutoSchema): user = ma.Nested("UserSchema", exclude=("addresses", "cards", "password", "cart", "product_rating", "forget_tokens")) class Meta: model = ProductRating exclude = ("product", )
class UserSchema(ma.SQLAlchemyAutoSchema): addresses = ma.List(ma.Nested("AddressSchema", exclude=("user", )), dump_only=True) cards = ma.List(ma.Nested("CardSchema", exclude=("user", )), dump_only=True) cart = ma.Nested("UserCartSchema", exclude=("user", ), dump_only=True) product_rating = ma.List(ma.Nested("ProductRatingSchema", exclude=("user", "product")), dump_only=True) admin = ma.auto_field(dump_only=True) active = ma.auto_field(dump_only=True) enabled_2fa = ma.auto_field() email_verified = ma.auto_field(dump_only=True) email = fields.Email(required=True) username = fields.Str(required=True) password = fields.Str(required=True) class Meta: model = User
class ProductRatingSchema(ma.SQLAlchemyAutoSchema): user = ma.Nested("UserSchema", exclude=("addresses", "cards", "password", "cart", "product_rating", "admin", "enabled_2fa", "email_verified", "email", "id", "active")) rating = fields.Integer(required=True, validate=validate_rating) comments = fields.Str(required=True) class Meta: model = ProductRating exclude = ("product", )
class CardSchema(ma.SQLAlchemyAutoSchema): user = ma.Nested("UserSchema", exclude=("addresses", "cards", "password", "cart", "product_rating", "admin", "enabled_2fa", "email_verified", "email", "username", "active", "id")) number = fields.Str(required=True, validate=validate_card_number) cvc = fields.Str(required=True, validate=validate_cvc) expiry_year = fields.Str(required=True, validate=validate_expiry_year) expiry_month = fields.Str(required=True, validate=validate_expiry_month) class Meta: model = Card
class AddressSchema(ma.SQLAlchemyAutoSchema): user = ma.Nested("UserSchema", exclude=("addresses", "cards", "password", "cart", "product_rating", "admin", "enabled_2fa", "email_verified", "email", "username", "active", "id")) contact = fields.Str(validate=validate_contact) address_1 = fields.Str(validate=validate_address1) address_2 = fields.Str(validate=validate_address2) postal_code = fields.Str(validate=validate_postal_code) class Meta: model = Address
class OrderedProductSchema(ma.SQLAlchemyAutoSchema): product = ma.Nested("ProductSchema", exclude=("description", "pic_filename")) class Meta: model = OrderedProduct