28 lines
997 B
Python
28 lines
997 B
Python
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from sqlalchemy.orm import Session
|
|
from core.database import get_db
|
|
from schemas.contact import ContactCreate, ContactSchema
|
|
from helpers.contact_helpers import handle_contact_submission
|
|
|
|
router = APIRouter()
|
|
|
|
@router.post("/email", status_code=status.HTTP_201_CREATED, response_model=ContactSchema)
|
|
async def submit_contact_form(
|
|
contact_data: ContactCreate,
|
|
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 = handle_contact_submission(db=db, contact_data=contact_data.dict())
|
|
return contact
|
|
except HTTPException:
|
|
# Re-raise the HTTP exception from the helper
|
|
raise
|
|
except Exception as e:
|
|
raise HTTPException(
|
|
status_code=500,
|
|
detail={"message": "An error occurred processing your request", "error": str(e)}
|
|
) |