system-prompts-and-models-o.../salesflow-saas/backend/app/api/v1/sectors.py
Claude 84762f08ab
Add complete launch infrastructure: models, APIs, agents, compliance, docs, knowledge base
Phase 1 - Repo Hardening:
- README.md, LICENSE, SECURITY.md, CONTRIBUTING.md
- GitHub Actions repo-hygiene workflow
- docs/: ARCHITECTURE, DATA-MODEL, API-MAP, AGENT-MAP, DEPLOYMENT-NOTES

Phase 2 - Database Models (7 new):
- Company, Contact, Call, Commission, Payout, Dispute, GuaranteeClaim
- Consent, Complaint, Policy, KnowledgeArticle, SectorAsset
- Updated models/__init__.py with all 32+ models

Phase 3 - API Surfaces (16 new route files):
- companies, contacts, calls, meetings, commissions, payouts
- disputes, guarantees, consents, complaints, knowledge
- sectors, presentations, supervisor, admin, health
- Updated router.py with all 24 route groups

Phase 4 - AI Prompt Registry (18 agent contracts):
- Lead Qualification, Affiliate Recruitment Evaluator, Onboarding Coach
- Outreach Writer, Arabic WhatsApp, English Conversation, Voice Call
- Meeting Booking, Sector Strategist, Objection Handler
- Proposal Drafter, QA Reviewer, Compliance Reviewer
- Knowledge Retrieval, Revenue Attribution, Fraud Reviewer
- Guarantee Claim Reviewer, Management Summary

Phase 5 - Communication Templates:
- 15 production templates (WhatsApp, email, voice, internal)
- Arabic + English variants with variable interpolation

Phase 6 - Compliance Center (7 legal docs):
- Privacy policy, Terms of service, Refund policy
- Commission policy, Affiliate rules, Consent policy, Data protection
- All PDPL-compliant, Arabic

Phase 7 - Celery Workers (fully implemented):
- follow_up_tasks: automated lead follow-ups with workflow execution
- message_tasks: WhatsApp/email/SMS with retry logic
- notification_tasks: daily reports, meeting reminders, in-app notifications
- affiliate_tasks: target checking, commission calculation, weekly reports, AI outreach

Phase 8 - Knowledge Base OS (8 files):
- Services overview, Pricing policy, Channel policy, Meeting policy
- Identity rules, Escalation rules, Hiring path, Internal SOPs

https://claude.ai/code/session_01KnJgK7RwyeCvRZTRThHtfU
2026-03-31 07:57:48 +00:00

93 lines
2.8 KiB
Python

from fastapi import APIRouter, Depends, HTTPException, Query
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import select, func, distinct
from uuid import UUID
from datetime import datetime
from typing import Optional
from pydantic import BaseModel as Schema
from app.database import get_db
from app.api.deps import get_current_user
from app.models.user import User
from app.models.knowledge import SectorAsset
router = APIRouter()
class SectorAssetResponse(Schema):
id: UUID
sector: str
asset_type: str
title: str
title_ar: Optional[str] = None
content: Optional[str] = None
content_ar: Optional[str] = None
file_url: Optional[str] = None
metadata: Optional[dict] = None
is_active: bool
created_at: datetime
model_config = {"from_attributes": True}
class SectorAssetListResponse(Schema):
items: list[SectorAssetResponse]
total: int
class SectorSummary(Schema):
sector: str
asset_count: int
class SectorListResponse(Schema):
sectors: list[SectorSummary]
@router.get("", response_model=SectorListResponse)
async def list_sectors(
current_user: User = Depends(get_current_user),
db: AsyncSession = Depends(get_db),
):
result = await db.execute(
select(SectorAsset.sector, func.count(SectorAsset.id))
.where(SectorAsset.is_active == True)
.group_by(SectorAsset.sector)
.order_by(SectorAsset.sector)
)
sectors = [SectorSummary(sector=row[0], asset_count=row[1]) for row in result.all()]
return SectorListResponse(sectors=sectors)
@router.get("/{sector}/assets", response_model=SectorAssetListResponse)
async def get_sector_assets(
sector: str,
asset_type: str = Query(None),
current_user: User = Depends(get_current_user),
db: AsyncSession = Depends(get_db),
):
query = select(SectorAsset).where(SectorAsset.sector == sector, SectorAsset.is_active == True)
if asset_type:
query = query.where(SectorAsset.asset_type == asset_type)
total = (await db.execute(select(func.count()).select_from(query.subquery()))).scalar()
result = await db.execute(query.order_by(SectorAsset.created_at.desc()))
items = [SectorAssetResponse.model_validate(a) for a in result.scalars().all()]
return SectorAssetListResponse(items=items, total=total)
@router.get("/{sector}/assets/{asset_id}", response_model=SectorAssetResponse)
async def get_sector_asset(
sector: str,
asset_id: UUID,
current_user: User = Depends(get_current_user),
db: AsyncSession = Depends(get_db),
):
result = await db.execute(
select(SectorAsset).where(SectorAsset.id == asset_id, SectorAsset.sector == sector)
)
asset = result.scalar_one_or_none()
if not asset:
raise HTTPException(status_code=404, detail="Sector asset not found")
return SectorAssetResponse.model_validate(asset)