29 lines
1003 B
Python
29 lines
1003 B
Python
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from sqlalchemy.orm import Session
|
|
from typing import Dict, Any
|
|
from core.database import get_db
|
|
from schemas.contact_form import ContactFormSchema
|
|
from helpers.contact_form_helpers import process_contact_form_submission
|
|
|
|
router = APIRouter()
|
|
|
|
@router.post("/email", status_code=status.HTTP_201_CREATED, response_model=ContactFormSchema)
|
|
async def submit_contact_form(
|
|
form_data: Dict[str, Any],
|
|
db: Session = Depends(get_db)
|
|
):
|
|
"""
|
|
Submit a contact form with name, email, and message.
|
|
All fields are required and email must be in valid format.
|
|
"""
|
|
try:
|
|
contact_form = process_contact_form_submission(db, form_data)
|
|
return contact_form
|
|
except HTTPException:
|
|
# Re-raise the HTTPException from the helper
|
|
raise
|
|
except Exception as e:
|
|
raise HTTPException(
|
|
status_code=500,
|
|
detail={"message": f"An unexpected error occurred: {str(e)}"}
|
|
) |