44 lines
998 B
Python
44 lines
998 B
Python
import pickle
|
|
from datetime import datetime, date
|
|
from typing import Optional
|
|
|
|
from pydantic import field_validator
|
|
|
|
from schemas.base import BaseSchema
|
|
|
|
|
|
# region Entities
|
|
|
|
class AttributeTypeSchema(BaseSchema):
|
|
id: int
|
|
type: str
|
|
name: str
|
|
is_deleted: bool
|
|
|
|
|
|
class AttributeSchema(BaseSchema):
|
|
id: int
|
|
label: str
|
|
name: str
|
|
is_applicable_to_group: bool
|
|
is_nullable: bool
|
|
default_value: Optional[bool | int | float | str | date | datetime]
|
|
type: AttributeTypeSchema
|
|
|
|
@field_validator("default_value", mode="before")
|
|
def validate_default_value(cls, value: Optional[bytes]):
|
|
return pickle.loads(value) if value else None
|
|
|
|
|
|
class CardAttributeSchema(BaseSchema):
|
|
value: Optional[bool | int | float | str | date | datetime]
|
|
card_id: int
|
|
attribute: AttributeSchema
|
|
|
|
@field_validator("value", mode="before")
|
|
def validate_value(cls, value: Optional[bytes]):
|
|
return pickle.loads(value) if value else None
|
|
|
|
|
|
# endregion
|