36 lines
969 B
Python
36 lines
969 B
Python
from pydantic import UUID4, PositiveInt, NegativeInt
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, field_validator
|
|
|
|
class BaseConfig:
|
|
json_encoders = {
|
|
datetime: lambda v: v.isoformat(), # Преобразует datetime в строку ISO
|
|
UUID4: lambda v: str(v), # Преобразует UUID в строку
|
|
}
|
|
|
|
|
|
class BaseModelWithSerializeDatetime(BaseModel):
|
|
@field_validator("*")
|
|
def remove_tzinfo(cls, value):
|
|
if isinstance(value, datetime) and value.tzinfo is not None:
|
|
return value.replace(tzinfo=None)
|
|
return value
|
|
|
|
class Config(BaseConfig):
|
|
pass
|
|
|
|
|
|
class MessageFromChatSchema(BaseModelWithSerializeDatetime):
|
|
id: PositiveInt
|
|
user_id: PositiveInt
|
|
chat_id: NegativeInt
|
|
text: str
|
|
message_time: datetime
|
|
|
|
|
|
class MessagesForSendToWorkersSchema(BaseModelWithSerializeDatetime):
|
|
slice_id: UUID4
|
|
messages: list[MessageFromChatSchema] |