Added documentation for the auto-population feature and the analytics integration.
This commit is contained in:
@@ -39,6 +39,52 @@ async def get_onboarding_data(
|
||||
db: Session = Depends(get_db)
|
||||
) -> Dict[str, Any]:
|
||||
"""Get onboarding data for enhanced strategy auto-population."""
|
||||
try:
|
||||
logger.warning(f"🔍 get_onboarding_data called with current_user: {current_user}")
|
||||
|
||||
# Extract authenticated user_id from Clerk
|
||||
clerk_user_id = str(current_user.get('id', ''))
|
||||
if not clerk_user_id:
|
||||
logger.error(f"❌ Invalid user ID in authentication token. current_user: {current_user}")
|
||||
raise HTTPException(
|
||||
status_code=401,
|
||||
detail="Invalid user ID in authentication token"
|
||||
)
|
||||
|
||||
# Clerk user IDs are strings (e.g., 'user_xxx' or numeric strings)
|
||||
# OnboardingSession uses Clerk user_id as String(255), so we can use it directly
|
||||
authenticated_user_id = clerk_user_id
|
||||
|
||||
logger.warning(f"🚀 Getting onboarding data for authenticated user: {authenticated_user_id}")
|
||||
|
||||
db_service = EnhancedStrategyDBService(db)
|
||||
enhanced_service = EnhancedStrategyService(db_service)
|
||||
|
||||
onboarding_data = await enhanced_service._get_onboarding_data(authenticated_user_id)
|
||||
|
||||
logger.warning(f"✅ Onboarding data retrieved successfully for user: {authenticated_user_id}")
|
||||
|
||||
return ResponseBuilder.create_success_response(
|
||||
message="Onboarding data retrieved successfully",
|
||||
data=onboarding_data
|
||||
)
|
||||
|
||||
except HTTPException as he:
|
||||
logger.error(f"❌ HTTPException in get_onboarding_data: status={he.status_code}, detail={he.detail}")
|
||||
raise
|
||||
except Exception as e:
|
||||
logger.error(f"❌ Error getting onboarding data: {str(e)}")
|
||||
logger.error(f"❌ Exception type: {type(e).__name__}")
|
||||
import traceback
|
||||
logger.error(f"❌ Traceback: {traceback.format_exc()}")
|
||||
raise ContentPlanningErrorHandler.handle_general_error(e, "get_onboarding_data")
|
||||
|
||||
@router.post("/smart-autofill")
|
||||
async def smart_autofill(
|
||||
current_user: Dict[str, Any] = Depends(get_current_user),
|
||||
db: Session = Depends(get_db)
|
||||
) -> Dict[str, Any]:
|
||||
"""Get smart autofill combining database fields (18-19) + AI fields (11-12)."""
|
||||
try:
|
||||
# Extract authenticated user_id from Clerk
|
||||
clerk_user_id = str(current_user.get('id', ''))
|
||||
@@ -48,32 +94,30 @@ async def get_onboarding_data(
|
||||
detail="Invalid user ID in authentication token"
|
||||
)
|
||||
|
||||
authenticated_user_id = int(clerk_user_id) if clerk_user_id.isdigit() else None
|
||||
if not authenticated_user_id:
|
||||
raise HTTPException(
|
||||
status_code=401,
|
||||
detail="Invalid user ID format in authentication token"
|
||||
)
|
||||
# Clerk user IDs are strings (e.g., 'user_xxx' or numeric strings)
|
||||
# OnboardingSession uses Clerk user_id as String(255), so we can use it directly
|
||||
authenticated_user_id = clerk_user_id
|
||||
|
||||
logger.info(f"🚀 Getting onboarding data for authenticated user: {authenticated_user_id}")
|
||||
logger.info(f"🚀 Starting smart autofill for authenticated user: {authenticated_user_id}")
|
||||
|
||||
db_service = EnhancedStrategyDBService(db)
|
||||
enhanced_service = EnhancedStrategyService(db_service)
|
||||
# Import unified service
|
||||
from ....services.content_strategy.autofill.unified_autofill_service import UnifiedAutoFillService
|
||||
|
||||
onboarding_data = await enhanced_service._get_onboarding_data(authenticated_user_id)
|
||||
unified_service = UnifiedAutoFillService(db)
|
||||
autofill_data = await unified_service.get_autofill(authenticated_user_id)
|
||||
|
||||
logger.info(f"✅ Onboarding data retrieved successfully for user: {authenticated_user_id}")
|
||||
logger.info(f"✅ Smart autofill completed successfully for user: {authenticated_user_id}")
|
||||
|
||||
return ResponseBuilder.create_success_response(
|
||||
message="Onboarding data retrieved successfully",
|
||||
data=onboarding_data
|
||||
message="Smart autofill completed successfully",
|
||||
data=autofill_data
|
||||
)
|
||||
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
logger.error(f"❌ Error getting onboarding data: {str(e)}")
|
||||
raise ContentPlanningErrorHandler.handle_general_error(e, "get_onboarding_data")
|
||||
logger.error(f"❌ Error in smart autofill: {str(e)}")
|
||||
raise ContentPlanningErrorHandler.handle_general_error(e, "smart_autofill")
|
||||
|
||||
@router.get("/tooltips")
|
||||
async def get_enhanced_strategy_tooltips(
|
||||
@@ -255,12 +299,9 @@ async def clear_streaming_cache(
|
||||
detail="Invalid user ID in authentication token"
|
||||
)
|
||||
|
||||
authenticated_user_id = int(clerk_user_id) if clerk_user_id.isdigit() else None
|
||||
if not authenticated_user_id:
|
||||
raise HTTPException(
|
||||
status_code=401,
|
||||
detail="Invalid user ID format in authentication token"
|
||||
)
|
||||
# Clerk user IDs are strings (e.g., 'user_xxx' or numeric strings)
|
||||
# Cache keys use the Clerk user_id directly
|
||||
authenticated_user_id = clerk_user_id
|
||||
|
||||
logger.info(f"🚀 Clearing streaming cache for authenticated user: {authenticated_user_id}")
|
||||
|
||||
|
||||
@@ -18,15 +18,19 @@ from .endpoints.ai_generation_endpoints import router as ai_generation_router
|
||||
router = APIRouter(prefix="/enhanced-strategies", tags=["Content Strategy"])
|
||||
|
||||
# Include all endpoint routers
|
||||
# CRUD endpoints directly under /enhanced-strategies (backward compatibility)
|
||||
router.include_router(crud_router, prefix="")
|
||||
# Analytics endpoints under /enhanced-strategies/strategies/{id}/...
|
||||
router.include_router(analytics_router, prefix="/strategies")
|
||||
# Utility endpoints directly under /enhanced-strategies
|
||||
# IMPORTANT: Specific routes (like /onboarding-data) must come BEFORE parameterized routes (like /{strategy_id})
|
||||
# to avoid route conflicts where FastAPI tries to parse "onboarding-data" as strategy_id
|
||||
|
||||
# Utility endpoints directly under /enhanced-strategies (must come first - has /onboarding-data)
|
||||
router.include_router(utility_router, prefix="")
|
||||
# Streaming endpoints directly under /enhanced-strategies
|
||||
router.include_router(streaming_router, prefix="")
|
||||
# Autofill endpoints under /enhanced-strategies/strategies/{id}/...
|
||||
router.include_router(autofill_router, prefix="/strategies")
|
||||
# AI generation endpoints under /enhanced-strategies/ai-generation
|
||||
router.include_router(ai_generation_router, prefix="/ai-generation")
|
||||
router.include_router(ai_generation_router, prefix="/ai-generation")
|
||||
# CRUD endpoints directly under /enhanced-strategies (backward compatibility)
|
||||
# This includes /{strategy_id} route, so it must come AFTER specific routes
|
||||
router.include_router(crud_router, prefix="")
|
||||
# Analytics endpoints under /enhanced-strategies/strategies/{id}/...
|
||||
router.include_router(analytics_router, prefix="/strategies")
|
||||
# Autofill endpoints under /enhanced-strategies/strategies/{id}/...
|
||||
router.include_router(autofill_router, prefix="/strategies")
|
||||
Reference in New Issue
Block a user