feat: implement contact form submission endpoint with validation

This commit is contained in:
Backend IM Bot 2025-04-28 13:35:10 +00:00
parent abc44b43e7
commit e3f46073ef

View File

@ -12,10 +12,10 @@ async def submit_contact_form(
db: Session = Depends(get_db) db: Session = Depends(get_db)
): ):
""" """
Submit a contact form with name, email, and message. Submit a new contact form with name, email, and message.
All fields are required and email must be in valid format. All fields are required and email must be in valid format.
""" """
# Validate the contact form data # Validate the form data
errors = validate_contact_form_data({ errors = validate_contact_form_data({
"name": contact_form.name, "name": contact_form.name,
"email": contact_form.email, "email": contact_form.email,
@ -29,10 +29,15 @@ async def submit_contact_form(
detail=errors detail=errors
) )
# Create the contact form entry in the database # Create the contact form in the database
create_contact_form(db=db, contact_form_data=contact_form) created_form = create_contact_form(db=db, contact_form_data=contact_form)
return { return {
"status": "success", "status": "success",
"message": "Contact form submitted successfully" "message": "Contact form submitted successfully",
"data": {
"id": created_form.id,
"name": created_form.name,
"email": created_form.email
}
} }