diff --git a/endpoints/form.post.py b/endpoints/form.post.py index e69de29..cbfe51d 100644 --- a/endpoints/form.post.py +++ b/endpoints/form.post.py @@ -0,0 +1,31 @@ +from fastapi import APIRouter, Depends, HTTPException, status +from sqlalchemy.orm import Session +from core.database import get_db +from schemas.contact_form import ContactFormCreate +from helpers.contact_form_helpers import handle_contact_form_submission + +router = APIRouter() + +@router.post("/form", status_code=status.HTTP_201_CREATED) +async def submit_contact_form( + form_data: ContactFormCreate, + 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: + result = handle_contact_form_submission( + db=db, + form_data=form_data.dict() + ) + return result + except HTTPException: + # Re-raise the HTTPException from the helper + raise + except Exception as e: + raise HTTPException( + status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, + detail=f"An error occurred while processing the form: {str(e)}" + ) \ No newline at end of file