From 6fa53d63bf0949734f3bd75bb7fc9846db50bc87 Mon Sep 17 00:00:00 2001 From: Floke Date: Mon, 2 Mar 2026 10:28:07 +0000 Subject: [PATCH] [31388f42] CE Backend: Add missing POST /api/contacts endpoint to support external contact ingestion --- company-explorer/backend/app.py | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/company-explorer/backend/app.py b/company-explorer/backend/app.py index 10b63be7..29a74763 100644 --- a/company-explorer/backend/app.py +++ b/company-explorer/backend/app.py @@ -68,6 +68,15 @@ class CompanyCreate(BaseModel): website: 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): names: List[str] @@ -631,6 +640,42 @@ def bulk_import_companies(req: BulkImportRequest, background_tasks: BackgroundTa db.commit() 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") 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()