[31388f42] CE Backend: Add missing POST /api/contacts endpoint to support external contact ingestion
This commit is contained in:
@@ -68,6 +68,15 @@ class CompanyCreate(BaseModel):
|
|||||||
website: Optional[str] = None
|
website: Optional[str] = None
|
||||||
crm_id: Optional[str] = None
|
crm_id: Optional[str] = None
|
||||||
|
|
||||||
|
class ContactCreate(BaseModel):
|
||||||
|
company_id: int
|
||||||
|
first_name: Optional[str] = None
|
||||||
|
last_name: Optional[str] = None
|
||||||
|
email: Optional[str] = None
|
||||||
|
job_title: Optional[str] = None
|
||||||
|
role: Optional[str] = None
|
||||||
|
is_primary: bool = True
|
||||||
|
|
||||||
class BulkImportRequest(BaseModel):
|
class BulkImportRequest(BaseModel):
|
||||||
names: List[str]
|
names: List[str]
|
||||||
|
|
||||||
@@ -631,6 +640,42 @@ def bulk_import_companies(req: BulkImportRequest, background_tasks: BackgroundTa
|
|||||||
db.commit()
|
db.commit()
|
||||||
return {"status": "success", "imported": imported_count}
|
return {"status": "success", "imported": imported_count}
|
||||||
|
|
||||||
|
@app.post("/api/contacts")
|
||||||
|
def create_contact_endpoint(contact: ContactCreate, db: Session = Depends(get_db), username: str = Depends(authenticate_user)):
|
||||||
|
# Check if company exists
|
||||||
|
company = db.query(Company).filter(Company.id == contact.company_id).first()
|
||||||
|
if not company:
|
||||||
|
raise HTTPException(status_code=404, detail="Company not found")
|
||||||
|
|
||||||
|
# Check if contact with same email already exists for this company
|
||||||
|
if contact.email:
|
||||||
|
existing = db.query(Contact).filter(Contact.company_id == contact.company_id, Contact.email == contact.email).first()
|
||||||
|
if existing:
|
||||||
|
# Update existing contact
|
||||||
|
existing.first_name = contact.first_name
|
||||||
|
existing.last_name = contact.last_name
|
||||||
|
existing.job_title = contact.job_title
|
||||||
|
existing.role = contact.role
|
||||||
|
db.commit()
|
||||||
|
db.refresh(existing)
|
||||||
|
return existing
|
||||||
|
|
||||||
|
new_contact = Contact(
|
||||||
|
company_id=contact.company_id,
|
||||||
|
first_name=contact.first_name,
|
||||||
|
last_name=contact.last_name,
|
||||||
|
email=contact.email,
|
||||||
|
job_title=contact.job_title,
|
||||||
|
role=contact.role,
|
||||||
|
is_primary=contact.is_primary,
|
||||||
|
status="ACTIVE",
|
||||||
|
unsubscribe_token=str(uuid.uuid4())
|
||||||
|
)
|
||||||
|
db.add(new_contact)
|
||||||
|
db.commit()
|
||||||
|
db.refresh(new_contact)
|
||||||
|
return new_contact
|
||||||
|
|
||||||
@app.post("/api/companies/{company_id}/override/wikipedia")
|
@app.post("/api/companies/{company_id}/override/wikipedia")
|
||||||
def override_wikipedia(company_id: int, url: str, background_tasks: BackgroundTasks, db: Session = Depends(get_db), username: str = Depends(authenticate_user)):
|
def override_wikipedia(company_id: int, url: str, background_tasks: BackgroundTasks, db: Session = Depends(get_db), username: str = Depends(authenticate_user)):
|
||||||
company = db.query(Company).filter(Company.id == company_id).first()
|
company = db.query(Company).filter(Company.id == company_id).first()
|
||||||
|
|||||||
Reference in New Issue
Block a user