Recovered state: integrated TrendSurferAgent, restored frontend/backend files, and cleaned up recovery scripts
This commit is contained in:
@@ -8,12 +8,14 @@ from sqlalchemy.orm import Session
|
||||
from loguru import logger
|
||||
|
||||
from models.onboarding import OnboardingSession, WebsiteAnalysis, APIKey, ResearchPreferences
|
||||
from api.content_planning.services.content_strategy.onboarding import OnboardingDataIntegrationService
|
||||
|
||||
class UserDataService:
|
||||
"""Service for managing user data from onboarding."""
|
||||
|
||||
def __init__(self, db_session: Session):
|
||||
self.db = db_session
|
||||
self.integration_service = OnboardingDataIntegrationService()
|
||||
|
||||
def get_user_website_url(self, user_id: int = 1) -> Optional[str]:
|
||||
"""
|
||||
@@ -26,32 +28,26 @@ class UserDataService:
|
||||
Website URL or None if not found
|
||||
"""
|
||||
try:
|
||||
# Get the latest onboarding session for the user
|
||||
session = self.db.query(OnboardingSession).filter(
|
||||
OnboardingSession.user_id == user_id
|
||||
).order_by(OnboardingSession.updated_at.desc()).first()
|
||||
|
||||
if not session:
|
||||
logger.warning(f"No onboarding session found for user {user_id}")
|
||||
return None
|
||||
|
||||
# Get the latest website analysis for this session
|
||||
website_analysis = self.db.query(WebsiteAnalysis).filter(
|
||||
WebsiteAnalysis.session_id == session.id
|
||||
).order_by(WebsiteAnalysis.updated_at.desc()).first()
|
||||
# Use SSOT integration service
|
||||
integrated_data = self.integration_service.get_integrated_data_sync(str(user_id), self.db)
|
||||
website_analysis = integrated_data.get('website_analysis', {})
|
||||
|
||||
if not website_analysis:
|
||||
logger.warning(f"No website analysis found for session {session.id}")
|
||||
logger.warning(f"No website analysis found for user {user_id}")
|
||||
return None
|
||||
|
||||
logger.info(f"Found website URL: {website_analysis.website_url}")
|
||||
return website_analysis.website_url
|
||||
url = website_analysis.get('website_url')
|
||||
if url:
|
||||
logger.info(f"Found website URL: {url}")
|
||||
return url
|
||||
|
||||
return None
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting user website URL: {str(e)}")
|
||||
return None
|
||||
|
||||
def get_user_onboarding_data(self, user_id: int = 1) -> Optional[Dict[str, Any]]:
|
||||
def get_user_onboarding_data(self, user_id: str) -> Optional[Dict[str, Any]]:
|
||||
"""
|
||||
Get comprehensive onboarding data for a user.
|
||||
|
||||
@@ -62,54 +58,25 @@ class UserDataService:
|
||||
Dictionary with onboarding data or None if not found
|
||||
"""
|
||||
try:
|
||||
# Get the latest onboarding session
|
||||
session = self.db.query(OnboardingSession).filter(
|
||||
OnboardingSession.user_id == user_id
|
||||
).order_by(OnboardingSession.updated_at.desc()).first()
|
||||
# Use SSOT integration service
|
||||
integrated_data = self.integration_service.get_integrated_data_sync(user_id, self.db)
|
||||
|
||||
if not session:
|
||||
if not integrated_data.get('onboarding_session'):
|
||||
return None
|
||||
|
||||
# Get website analysis
|
||||
website_analysis = self.db.query(WebsiteAnalysis).filter(
|
||||
WebsiteAnalysis.session_id == session.id
|
||||
).order_by(WebsiteAnalysis.updated_at.desc()).first()
|
||||
|
||||
# Get API keys
|
||||
api_keys = self.db.query(APIKey).filter(
|
||||
APIKey.session_id == session.id
|
||||
).all()
|
||||
|
||||
# Get research preferences
|
||||
research_preferences = self.db.query(ResearchPreferences).filter(
|
||||
ResearchPreferences.session_id == session.id
|
||||
).first()
|
||||
|
||||
# Map SSOT data to legacy format expected by consumers
|
||||
return {
|
||||
'session': {
|
||||
'id': session.id,
|
||||
'current_step': session.current_step,
|
||||
'progress': session.progress,
|
||||
'started_at': session.started_at.isoformat() if session.started_at else None,
|
||||
'updated_at': session.updated_at.isoformat() if session.updated_at else None
|
||||
},
|
||||
'website_analysis': website_analysis.to_dict() if website_analysis else None,
|
||||
'api_keys': [
|
||||
{
|
||||
'id': key.id,
|
||||
'provider': key.provider,
|
||||
'created_at': key.created_at.isoformat() if key.created_at else None
|
||||
}
|
||||
for key in api_keys
|
||||
],
|
||||
'research_preferences': research_preferences.to_dict() if research_preferences else None
|
||||
'session': integrated_data.get('onboarding_session'),
|
||||
'website_analysis': integrated_data.get('website_analysis'),
|
||||
'api_keys': integrated_data.get('api_keys_data', {}).get('api_keys', []),
|
||||
'research_preferences': integrated_data.get('research_preferences')
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting user onboarding data: {str(e)}")
|
||||
return None
|
||||
|
||||
def get_user_website_analysis(self, user_id: int = 1) -> Optional[Dict[str, Any]]:
|
||||
def get_user_website_analysis(self, user_id: str) -> Optional[Dict[str, Any]]:
|
||||
"""
|
||||
Get website analysis data for a user.
|
||||
|
||||
@@ -120,24 +87,10 @@ class UserDataService:
|
||||
Website analysis data or None if not found
|
||||
"""
|
||||
try:
|
||||
# Get the latest onboarding session
|
||||
session = self.db.query(OnboardingSession).filter(
|
||||
OnboardingSession.user_id == user_id
|
||||
).order_by(OnboardingSession.updated_at.desc()).first()
|
||||
|
||||
if not session:
|
||||
return None
|
||||
|
||||
# Get website analysis
|
||||
website_analysis = self.db.query(WebsiteAnalysis).filter(
|
||||
WebsiteAnalysis.session_id == session.id
|
||||
).order_by(WebsiteAnalysis.updated_at.desc()).first()
|
||||
|
||||
if not website_analysis:
|
||||
return None
|
||||
|
||||
return website_analysis.to_dict()
|
||||
# Use SSOT integration service
|
||||
integrated_data = self.integration_service.get_integrated_data_sync(user_id, self.db)
|
||||
return integrated_data.get('website_analysis')
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting user website analysis: {str(e)}")
|
||||
return None
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user