From f417477a20fc49a2ab5b5707ac880759d652e2a2 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Mon, 28 Apr 2025 17:31:03 +0000 Subject: [PATCH] feat: add contact form submission endpoint with validation --- endpoints/form.post.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) 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