Website contact form endpoint
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
from enum import Enum
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, EmailStr, Field, validator
|
||||
|
||||
|
||||
class ContactEnquiryType(str, Enum):
|
||||
GENERAL = "general"
|
||||
AVIATION_BUSINESS = "aviation_business"
|
||||
PILOT = "pilot"
|
||||
EVENTS = "events"
|
||||
COMMUNITY = "community"
|
||||
|
||||
|
||||
class ContactRequestCreate(BaseModel):
|
||||
name: str = Field(..., max_length=128)
|
||||
email: EmailStr
|
||||
phone: Optional[str] = Field(None, max_length=32)
|
||||
enquiry_type: ContactEnquiryType
|
||||
subject: str = Field(..., max_length=160)
|
||||
message: str = Field(..., min_length=1, max_length=4000)
|
||||
source_page: Optional[str] = Field(None, max_length=256)
|
||||
|
||||
@validator("name", "subject", "message")
|
||||
def validate_required_text(cls, value):
|
||||
value = value.strip()
|
||||
if not value:
|
||||
raise ValueError("Field is required")
|
||||
return value
|
||||
|
||||
@validator("phone", "source_page")
|
||||
def strip_optional_text(cls, value):
|
||||
if value is None:
|
||||
return value
|
||||
value = value.strip()
|
||||
return value or None
|
||||
|
||||
|
||||
class ContactRequestReceipt(BaseModel):
|
||||
status: str = "received"
|
||||
Reference in New Issue
Block a user