Fix test failures and workload/websocket behavior
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, status, Query, Request
|
||||
import uuid
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import Optional
|
||||
|
||||
@@ -8,7 +9,7 @@ from app.core.config import settings
|
||||
from app.models import User, ReportHistory, ScheduledReport
|
||||
from app.schemas.report import (
|
||||
WeeklyReportContent, ReportHistoryListResponse, ReportHistoryItem,
|
||||
GenerateReportResponse, ReportSummary
|
||||
GenerateReportResponse, ReportSummary, WeeklyReportSubscription, WeeklyReportSubscriptionUpdate
|
||||
)
|
||||
from app.middleware.auth import get_current_user
|
||||
from app.services.report_service import ReportService
|
||||
@@ -16,6 +17,62 @@ from app.services.report_service import ReportService
|
||||
router = APIRouter(tags=["reports"])
|
||||
|
||||
|
||||
@router.get("/api/reports/weekly/subscription", response_model=WeeklyReportSubscription)
|
||||
async def get_weekly_report_subscription(
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
"""
|
||||
Get weekly report subscription status for the current user.
|
||||
"""
|
||||
scheduled_report = db.query(ScheduledReport).filter(
|
||||
ScheduledReport.recipient_id == current_user.id,
|
||||
ScheduledReport.report_type == "weekly",
|
||||
).first()
|
||||
|
||||
if not scheduled_report:
|
||||
return WeeklyReportSubscription(is_active=False, last_sent_at=None)
|
||||
|
||||
return WeeklyReportSubscription(
|
||||
is_active=scheduled_report.is_active,
|
||||
last_sent_at=scheduled_report.last_sent_at,
|
||||
)
|
||||
|
||||
|
||||
@router.put("/api/reports/weekly/subscription", response_model=WeeklyReportSubscription)
|
||||
async def update_weekly_report_subscription(
|
||||
subscription: WeeklyReportSubscriptionUpdate,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
"""
|
||||
Update weekly report subscription status for the current user.
|
||||
"""
|
||||
scheduled_report = db.query(ScheduledReport).filter(
|
||||
ScheduledReport.recipient_id == current_user.id,
|
||||
ScheduledReport.report_type == "weekly",
|
||||
).first()
|
||||
|
||||
if not scheduled_report:
|
||||
scheduled_report = ScheduledReport(
|
||||
id=str(uuid.uuid4()),
|
||||
report_type="weekly",
|
||||
recipient_id=current_user.id,
|
||||
is_active=subscription.is_active,
|
||||
)
|
||||
db.add(scheduled_report)
|
||||
else:
|
||||
scheduled_report.is_active = subscription.is_active
|
||||
|
||||
db.commit()
|
||||
db.refresh(scheduled_report)
|
||||
|
||||
return WeeklyReportSubscription(
|
||||
is_active=scheduled_report.is_active,
|
||||
last_sent_at=scheduled_report.last_sent_at,
|
||||
)
|
||||
|
||||
|
||||
@router.get("/api/reports/weekly/preview", response_model=WeeklyReportContent)
|
||||
async def preview_weekly_report(
|
||||
db: Session = Depends(get_db),
|
||||
|
||||
Reference in New Issue
Block a user