[31f88f42] Keine neuen Commits in dieser Session.
Keine neuen Commits in dieser Session.
This commit is contained in:
@@ -107,6 +107,12 @@ class ReportMistakeRequest(BaseModel):
|
||||
quote: Optional[str] = None
|
||||
user_comment: Optional[str] = None
|
||||
|
||||
class CompanyMatchRequest(BaseModel):
|
||||
name: str
|
||||
website: Optional[str] = None
|
||||
city: Optional[str] = None
|
||||
country: Optional[str] = "Deutschland"
|
||||
|
||||
class ProvisioningRequest(BaseModel):
|
||||
so_contact_id: int
|
||||
so_person_id: Optional[int] = None
|
||||
@@ -302,6 +308,58 @@ def unsubscribe_contact(token: str, db: Session = Depends(get_db)):
|
||||
def health_check(username: str = Depends(authenticate_user)):
|
||||
return {"status": "ok", "version": settings.VERSION, "db": settings.DATABASE_URL}
|
||||
|
||||
@app.post("/api/match-company/reload")
|
||||
async def reload_matching_service(db: Session = Depends(get_db), username: str = Depends(authenticate_user)):
|
||||
"""
|
||||
Forces the matching service (Deduplicator) to reload all company records from DB.
|
||||
Should be called after major imports or SuperOffice syncs.
|
||||
"""
|
||||
try:
|
||||
app.state.deduplicator = Deduplicator(db)
|
||||
return {
|
||||
"status": "success",
|
||||
"records_loaded": len(app.state.deduplicator.reference_data)
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to reload matching service: {e}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
@app.post("/api/match-company")
|
||||
async def match_company(request: CompanyMatchRequest, db: Session = Depends(get_db), username: str = Depends(authenticate_user)):
|
||||
"""
|
||||
Centralized Account Matching Service.
|
||||
Checks if a company already exists in SuperOffice (via Company Explorer DB).
|
||||
Returns list of matches with scores and CRM IDs.
|
||||
"""
|
||||
try:
|
||||
# Lazy initialization of Deduplicator
|
||||
if not hasattr(app.state, 'deduplicator'):
|
||||
logger.info("Initializing Deduplicator for the first time...")
|
||||
app.state.deduplicator = Deduplicator(db)
|
||||
|
||||
# Prepare Candidate dict for the service
|
||||
candidate = {
|
||||
'name': request.name,
|
||||
'website': request.website,
|
||||
'city': request.city,
|
||||
'country': request.country
|
||||
}
|
||||
|
||||
results = app.state.deduplicator.find_duplicates(candidate)
|
||||
|
||||
# Return structured results
|
||||
return {
|
||||
"query": candidate,
|
||||
"match_found": len(results) > 0,
|
||||
"best_match": results[0] if results else None,
|
||||
"all_matches": results
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"Error in company matching: {e}")
|
||||
import traceback
|
||||
logger.error(traceback.format_exc())
|
||||
raise HTTPException(status_code=500, detail=f"Matching failed: {str(e)}")
|
||||
|
||||
@app.post("/api/provision/superoffice-contact", response_model=ProvisioningResponse)
|
||||
def provision_superoffice_contact(
|
||||
req: ProvisioningRequest,
|
||||
|
||||
Reference in New Issue
Block a user