feat: add contact form submission endpoint with validation
This commit is contained in:
parent
4d6d400003
commit
f417477a20
@ -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)}"
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user