Add Message schema
This commit is contained in:
parent
e7520b1987
commit
b64bff54a7
@ -1,39 +1,35 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Optional
|
||||
from datetime import datetime
|
||||
from uuid import UUID
|
||||
|
||||
class MessageBase(BaseModel):
|
||||
content: str = Field(..., min_length=1, description="Message content")
|
||||
sender_id: UUID = Field(..., description="ID of the message sender")
|
||||
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 Config:
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"content": "Hello, how are you?",
|
||||
"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):
|
||||
id: UUID
|
||||
is_read: bool = False
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"id": "123e4567-e89b-12d3-a456-426614174000",
|
||||
"content": "Hello, how are you?",
|
||||
"id": "123e4567-e89b-12d3-a456-426614174002",
|
||||
"sender_id": "123e4567-e89b-12d3-a456-426614174000",
|
||||
"receiver_id": "987fcdeb-51a2-3b4c-9d0e-142357468000",
|
||||
"is_read": False,
|
||||
"created_at": "2023-01-01T00:00:00",
|
||||
"updated_at": "2023-01-01T00:00:00"
|
||||
"receiver_id": "123e4567-e89b-12d3-a456-426614174001",
|
||||
"content": "Hello, how are you?",
|
||||
"is_read": False
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user