"""API endpoints for summary management - unified access to all summaries.""" from fastapi import APIRouter, HTTPException, Query from pydantic import BaseModel from typing import List, Optional from datetime import datetime from ..services.database_storage_service import database_storage_service router = APIRouter(prefix="/api/summaries", tags=["summaries"]) class SummaryResponse(BaseModel): """Response model for summary data.""" id: str video_id: str video_url: str video_title: Optional[str] = None channel_name: Optional[str] = None summary: Optional[str] = None key_points: Optional[List[str]] = None main_themes: Optional[List[str]] = None model_used: Optional[str] = None processing_time: Optional[float] = None quality_score: Optional[float] = None summary_length: Optional[str] = None focus_areas: Optional[List[str]] = None source: Optional[str] = None created_at: Optional[datetime] = None class Config: from_attributes = True @router.get("/", response_model=List[SummaryResponse]) async def list_summaries( limit: int = Query(10, ge=1, le=100, description="Maximum results"), skip: int = Query(0, ge=0, description="Skip results"), model: Optional[str] = Query(None, description="Filter by AI model"), source: Optional[str] = Query(None, description="Filter by source") ): """List summaries with filtering options.""" try: summaries = database_storage_service.list_summaries( limit=limit, skip=skip, model=model, source=source ) return [SummaryResponse.from_orm(s) for s in summaries] except Exception as e: raise HTTPException(status_code=500, detail=f"Failed to list summaries: {str(e)}") @router.get("/stats") async def get_summary_stats(): """Get summary statistics.""" try: return database_storage_service.get_summary_stats() except Exception as e: raise HTTPException(status_code=500, detail=f"Failed to get stats: {str(e)}") @router.get("/{summary_id}", response_model=SummaryResponse) async def get_summary(summary_id: str): """Get a specific summary by ID.""" try: summary = database_storage_service.get_summary(summary_id) if not summary: raise HTTPException(status_code=404, detail="Summary not found") return SummaryResponse.from_orm(summary) except HTTPException: raise except Exception as e: raise HTTPException(status_code=500, detail=f"Failed to get summary: {str(e)}")