You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cookie-api/cookie_api/schema.py

26 lines
930 B
Python

from marshmallow import Schema, fields, ValidationError
def non_neg(value):
if not value >= 0:
raise ValidationError('Value cannot be negative')
def non_neg_non_zero(value):
if not value > 0:
raise ValidationError('Value cannot be negative or zero')
class CookieSchema(Schema):
id = fields.Int(dump_only=True)
created_date = fields.DateTime(dump_only=True)
modified_date = fields.DateTime()
name = fields.Str(required=True, error_messages={'required': "Cookie name is required"})
recipe_url = fields.Str()
sku = fields.Str(required=True, error_messages={'required': "Cookie sku is required"})
qoh = fields.Int(validate=non_neg, required=True, error_messages={'required': "Cookie qoh is required"})
unit_cost = fields.Decimal(validate=non_neg_non_zero, required=True, error_messages={'required': "Cookie unit_cost is required"})
class Meta:
ordered = True