Add Message schema

This commit is contained in:
Backend IM Bot 2025-03-26 08:01:31 +00:00
parent e7520b1987
commit b64bff54a7

View File

@ -1,39 +1,35 @@
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
from typing import Optional from typing import Optional
from datetime import datetime
from uuid import UUID from uuid import UUID
class MessageBase(BaseModel): class MessageBase(BaseModel):
content: str = Field(..., min_length=1, description="Message content")
sender_id: UUID = Field(..., description="ID of the message sender") sender_id: UUID = Field(..., description="ID of the message sender")
receiver_id: UUID = Field(..., description="ID of the message receiver") receiver_id: UUID = Field(..., description="ID of the message receiver")
content: str = Field(..., min_length=1, description="Content of the message")
is_read: bool = Field(default=False, description="Message read status")
class MessageCreate(MessageBase): class MessageCreate(MessageBase):
class Config: class Config:
schema_extra = { schema_extra = {
"example": { "example": {
"content": "Hello, how are you?",
"sender_id": "123e4567-e89b-12d3-a456-426614174000", "sender_id": "123e4567-e89b-12d3-a456-426614174000",
"receiver_id": "987fcdeb-51a2-3b4c-9d0e-142357468000" "receiver_id": "123e4567-e89b-12d3-a456-426614174001",
"content": "Hello, how are you?",
"is_read": False
} }
} }
class Message(MessageBase): class Message(MessageBase):
id: UUID id: UUID
is_read: bool = False
created_at: datetime
updated_at: datetime
class Config: class Config:
orm_mode = True orm_mode = True
schema_extra = { schema_extra = {
"example": { "example": {
"id": "123e4567-e89b-12d3-a456-426614174000", "id": "123e4567-e89b-12d3-a456-426614174002",
"content": "Hello, how are you?",
"sender_id": "123e4567-e89b-12d3-a456-426614174000", "sender_id": "123e4567-e89b-12d3-a456-426614174000",
"receiver_id": "987fcdeb-51a2-3b4c-9d0e-142357468000", "receiver_id": "123e4567-e89b-12d3-a456-426614174001",
"is_read": False, "content": "Hello, how are you?",
"created_at": "2023-01-01T00:00:00", "is_read": False
"updated_at": "2023-01-01T00:00:00"
} }
} }