feat: Add endpoint to retrieve currently processing extractions and corresponding tests
This commit is contained in:
@@ -159,3 +159,47 @@ async def get_all_extractions( # noqa: PLR0913
|
||||
) from e
|
||||
else:
|
||||
return result
|
||||
|
||||
|
||||
@router.get("/processing/current")
|
||||
async def get_processing_extractions(
|
||||
current_user: Annotated[User, Depends(get_current_active_user_flexible)], # noqa: ARG001
|
||||
extraction_service: Annotated[ExtractionService, Depends(get_extraction_service)],
|
||||
) -> list[ExtractionInfo]:
|
||||
"""Get all currently processing extractions for showing ongoing toasts."""
|
||||
try:
|
||||
# Get all extractions with processing status
|
||||
processing_extractions = await extraction_service.extraction_repo.get_by_status(
|
||||
"processing"
|
||||
)
|
||||
|
||||
# Convert to ExtractionInfo format
|
||||
result = []
|
||||
for extraction in processing_extractions:
|
||||
# Get user information
|
||||
user = await extraction_service.user_repo.get_by_id(extraction.user_id)
|
||||
user_name = user.name if user else None
|
||||
|
||||
extraction_info: ExtractionInfo = {
|
||||
"id": extraction.id or 0,
|
||||
"url": extraction.url,
|
||||
"service": extraction.service,
|
||||
"service_id": extraction.service_id,
|
||||
"title": extraction.title,
|
||||
"status": extraction.status,
|
||||
"error": extraction.error,
|
||||
"sound_id": extraction.sound_id,
|
||||
"user_id": extraction.user_id,
|
||||
"user_name": user_name,
|
||||
"created_at": extraction.created_at.isoformat(),
|
||||
"updated_at": extraction.updated_at.isoformat(),
|
||||
}
|
||||
result.append(extraction_info)
|
||||
|
||||
return result
|
||||
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"Failed to get processing extractions: {e!s}",
|
||||
) from e
|
||||
|
||||
Reference in New Issue
Block a user