17 lines
631 B
Python
17 lines
631 B
Python
from fastapi import APIRouter, HTTPException, status
|
|
from schemas.contact import ContactCreate
|
|
from helpers.contact_helpers import create_contact, validate_contact_data
|
|
|
|
router = APIRouter()
|
|
|
|
@router.post("/contact-us", status_code=status.HTTP_201_CREATED)
|
|
async def create_new_contact(contact: ContactCreate):
|
|
"""Create a new contact"""
|
|
if not validate_contact_data(contact):
|
|
raise HTTPException(status_code=400, detail="Invalid contact data")
|
|
|
|
new_contact = create_contact(contact)
|
|
if not new_contact:
|
|
raise HTTPException(status_code=400, detail="Failed to create contact")
|
|
|
|
return new_contact |