feat: implement contact form submission endpoint with validation
This commit is contained in:
parent
abc44b43e7
commit
e3f46073ef
@ -12,10 +12,10 @@ async def submit_contact_form(
|
||||
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.
|
||||
"""
|
||||
# Validate the contact form data
|
||||
# Validate the form data
|
||||
errors = validate_contact_form_data({
|
||||
"name": contact_form.name,
|
||||
"email": contact_form.email,
|
||||
@ -29,10 +29,15 @@ async def submit_contact_form(
|
||||
detail=errors
|
||||
)
|
||||
|
||||
# Create the contact form entry in the database
|
||||
create_contact_form(db=db, contact_form_data=contact_form)
|
||||
# Create the contact form in the database
|
||||
created_form = create_contact_form(db=db, contact_form_data=contact_form)
|
||||
|
||||
return {
|
||||
"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
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user