feat: Add endpoint to retrieve currently processing extractions and corresponding tests
Some checks failed
Backend CI / lint (push) Failing after 4m54s
Backend CI / test (push) Failing after 4m39s

This commit is contained in:
JSC
2025-08-24 13:44:01 +02:00
parent 16eb789539
commit d81a54207c
2 changed files with 89 additions and 0 deletions

View File

@@ -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