feat: Generated endpoint endpoints/email1.post.py via AI for Contact_form
This commit is contained in:
parent
bed5c09100
commit
3c5ca68443
@ -0,0 +1,40 @@
|
|||||||
|
from fastapi import APIRouter, Depends, HTTPException, status
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
from core.database import get_db
|
||||||
|
from schemas.contactform import ContactFormCreate, ContactFormSchema
|
||||||
|
from helpers.contactform_helpers import (
|
||||||
|
create_contact_form,
|
||||||
|
validate_contact_form_data,
|
||||||
|
format_validation_error_response,
|
||||||
|
send_notification_email
|
||||||
|
)
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
@router.post("/email1", status_code=status.HTTP_201_CREATED, response_model=ContactFormSchema)
|
||||||
|
async def submit_contact_form(
|
||||||
|
form_data: ContactFormCreate,
|
||||||
|
db: Session = Depends(get_db)
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Handle contact form submissions with fields: name, email, and message.
|
||||||
|
Validates all required fields and email format.
|
||||||
|
"""
|
||||||
|
# Validate the form data
|
||||||
|
validation_errors = validate_contact_form_data(form_data.dict())
|
||||||
|
|
||||||
|
# Return 400 with specific messages if validation fails
|
||||||
|
if validation_errors:
|
||||||
|
error_response = format_validation_error_response(validation_errors)
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
|
detail=error_response
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create the contact form entry in the database
|
||||||
|
contact_form = create_contact_form(db=db, form_data=form_data)
|
||||||
|
|
||||||
|
# Send notification email (this could be moved to a background task in production)
|
||||||
|
send_notification_email(ContactFormSchema.from_orm(contact_form))
|
||||||
|
|
||||||
|
return contact_form
|
Loading…
x
Reference in New Issue
Block a user