-
Notifications
You must be signed in to change notification settings - Fork 1
Remove React frontend and unify dev entrypoint #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,8 +6,17 @@ | |
| from fastapi.responses import StreamingResponse | ||
| from sqlalchemy.orm import Session | ||
| from app.core.database.database import get_db | ||
| from app.models.member import Member, Activity, Summary | ||
| from app.models.schemas import Activity as ActivitySchema, Summary as SummarySchema, DashboardStats, MonitoringResult, Member as MemberSchema | ||
| from app.models.member import Member, Activity, Summary, SocialProfile | ||
| from app.models.schemas import ( | ||
| Activity as ActivitySchema, | ||
| Summary as SummarySchema, | ||
| DashboardStats, | ||
| MonitoringResult, | ||
| Member as MemberSchema, | ||
| MonitoringQuickStartRequest, | ||
| MonitoringQuickStartResponse, | ||
| SocialProfile as SocialProfileSchema | ||
| ) | ||
| from app.services.monitors.monitor_manager import MonitorManager | ||
| from app.services.summarizers.llm_summarizer import LLMSummarizer | ||
| import json | ||
|
|
@@ -68,6 +77,68 @@ async def run_monitoring( | |
| ) | ||
|
|
||
|
|
||
| @router.post("/quick-start", response_model=MonitoringQuickStartResponse, status_code=status.HTTP_201_CREATED) | ||
| async def quick_start_monitoring( | ||
| payload: MonitoringQuickStartRequest, | ||
| db: Session = Depends(get_db) | ||
| ): | ||
| """Create a member profile and trigger monitoring in one request.""" | ||
| existing_member = db.query(Member).filter(Member.email == payload.email).first() | ||
| if existing_member: | ||
| member = existing_member | ||
| else: | ||
| member = Member( | ||
| name=payload.name, | ||
| email=payload.email, | ||
| position=payload.position, | ||
| department=payload.department | ||
| ) | ||
| db.add(member) | ||
| db.commit() | ||
| db.refresh(member) | ||
|
|
||
| existing_profile = db.query(SocialProfile).filter( | ||
| SocialProfile.member_id == member.id, | ||
| SocialProfile.platform == payload.platform | ||
| ).first() | ||
| if existing_profile: | ||
| profile = existing_profile | ||
| else: | ||
| profile = SocialProfile( | ||
| member_id=member.id, | ||
| platform=payload.platform, | ||
| profile_url=str(payload.profile_url), | ||
| username=payload.username | ||
| ) | ||
| db.add(profile) | ||
| db.commit() | ||
| db.refresh(profile) | ||
|
|
||
| monitor_manager = MonitorManager(db) | ||
| platform_key = payload.platform.lower() | ||
| if platform_key not in monitor_manager.monitors: | ||
| raise HTTPException( | ||
| status_code=status.HTTP_400_BAD_REQUEST, | ||
| detail=f"Unsupported platform: {payload.platform}" | ||
| ) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Platform validation occurs after database records are committedMedium Severity In the Additional Locations (2) |
||
|
|
||
| monitoring_result = None | ||
| if payload.run_monitoring: | ||
| activities = await monitor_manager.monitor_specific_profile(profile.id) | ||
| activity_payload = [ActivitySchema.from_orm(activity) for activity in activities] | ||
| monitoring_result = MonitoringResult( | ||
| status="completed", | ||
| new_activities=len(activities), | ||
| platform_results={profile.platform: activity_payload} | ||
| ) | ||
|
|
||
| return MonitoringQuickStartResponse( | ||
| member=MemberSchema.from_orm(member), | ||
| profile=SocialProfileSchema.from_orm(profile), | ||
| monitoring_result=monitoring_result | ||
| ) | ||
|
|
||
|
|
||
| @router.post("/monitor-profile/{profile_id}", status_code=status.HTTP_200_OK) | ||
| async def monitor_specific_profile( | ||
| profile_id: int, | ||
|
|
@@ -684,4 +755,4 @@ async def generate_member_summary( | |
| raise HTTPException( | ||
| status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, | ||
| detail=f"Member summary generation failed: {str(e)}" | ||
| ) | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The quick-start endpoint commits a new
SocialProfilebefore checking whether the requested platform is supported. If a client posts an unsupported platform, the API returns400but still leaves a persisted member/profile record that can never be monitored, polluting the database. Validate the platform prior to inserting or roll back on error to avoid creating unusable profiles.Useful? React with 👍 / 👎.