feat: Add filtering, searching, and sorting to user extractions retrieval
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, status
|
||||
from sqlmodel.ext.asyncio.session import AsyncSession
|
||||
|
||||
from app.core.database import get_db
|
||||
@@ -91,6 +91,10 @@ async def get_extraction(
|
||||
async def get_user_extractions(
|
||||
current_user: Annotated[User, Depends(get_current_active_user_flexible)],
|
||||
extraction_service: Annotated[ExtractionService, Depends(get_extraction_service)],
|
||||
search: Annotated[str | None, Query(description="Search in title, URL, or service")] = None,
|
||||
sort_by: Annotated[str, Query(description="Sort by field")] = "created_at",
|
||||
sort_order: Annotated[str, Query(description="Sort order (asc/desc)")] = "desc",
|
||||
status_filter: Annotated[str | None, Query(description="Filter by status")] = None,
|
||||
) -> dict[str, list[ExtractionInfo]]:
|
||||
"""Get all extractions for the current user."""
|
||||
try:
|
||||
@@ -100,7 +104,13 @@ async def get_user_extractions(
|
||||
detail="User ID not available",
|
||||
)
|
||||
|
||||
extractions = await extraction_service.get_user_extractions(current_user.id)
|
||||
extractions = await extraction_service.get_user_extractions(
|
||||
user_id=current_user.id,
|
||||
search=search,
|
||||
sort_by=sort_by,
|
||||
sort_order=sort_order,
|
||||
status_filter=status_filter,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
|
||||
Reference in New Issue
Block a user