feat: Add filtering, searching, and sorting to extraction retrieval endpoints

This commit is contained in:
JSC
2025-08-17 01:44:43 +02:00
parent 3326e406f8
commit 66d22df7dd
3 changed files with 126 additions and 11 deletions

View File

@@ -88,6 +88,34 @@ async def get_extraction(
@router.get("/")
async def get_all_extractions(
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 with optional filtering, search, and sorting."""
try:
extractions = await extraction_service.get_all_extractions(
search=search,
sort_by=sort_by,
sort_order=sort_order,
status_filter=status_filter,
)
except Exception as e:
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=f"Failed to get extractions: {e!s}",
) from e
else:
return {
"extractions": extractions,
}
@router.get("/user")
async def get_user_extractions(
current_user: Annotated[User, Depends(get_current_active_user_flexible)],
extraction_service: Annotated[ExtractionService, Depends(get_extraction_service)],