39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
from pydantic import BaseModel, EmailStr, Field
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
from uuid import UUID
|
|
|
|
# Base schema for ContactForm, used for inheritance
|
|
class ContactFormBase(BaseModel):
|
|
name: str = Field(..., description="Contact's name")
|
|
email: EmailStr = Field(..., description="Contact's email address")
|
|
message: str = Field(..., description="Contact message")
|
|
|
|
# Schema for creating a new ContactForm
|
|
class ContactFormCreate(ContactFormBase):
|
|
pass
|
|
|
|
# Schema for updating an existing ContactForm (all fields optional)
|
|
class ContactFormUpdate(BaseModel):
|
|
name: Optional[str] = Field(None, description="Contact's name")
|
|
email: Optional[EmailStr] = Field(None, description="Contact's email address")
|
|
message: Optional[str] = Field(None, description="Contact message")
|
|
|
|
# Schema for representing a ContactForm in responses
|
|
class ContactFormSchema(ContactFormBase):
|
|
id: UUID
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
schema_extra = {
|
|
"example": {
|
|
"id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
|
|
"name": "John Doe",
|
|
"email": "john.doe@example.com",
|
|
"message": "I would like more information about your services.",
|
|
"created_at": "2023-01-01T12:00:00",
|
|
"updated_at": "2023-01-01T12:00:00"
|
|
}
|
|
} |