feat(api): Add dedicated ClearDocumentsResponse class for document deletion endpoint

This commit is contained in:
yangdx
2025-03-31 19:13:27 +08:00
parent 1772e7a887
commit 04967b33cc

View File

@@ -59,6 +59,11 @@ class InsertResponse(BaseModel):
message: str = Field(description="Message describing the operation result") message: str = Field(description="Message describing the operation result")
class ClearDocumentsResponse(BaseModel):
status: str = Field(description="Status of the clear operation: success/partial_success/busy/fail")
message: str = Field(description="Message describing the operation result")
class DocStatusResponse(BaseModel): class DocStatusResponse(BaseModel):
@staticmethod @staticmethod
def format_datetime(dt: Any) -> Optional[str]: def format_datetime(dt: Any) -> Optional[str]:
@@ -755,7 +760,7 @@ def create_document_routes(
raise HTTPException(status_code=500, detail=str(e)) raise HTTPException(status_code=500, detail=str(e))
@router.delete( @router.delete(
"", response_model=InsertResponse, dependencies=[Depends(combined_auth)] "", response_model=ClearDocumentsResponse, dependencies=[Depends(combined_auth)]
) )
async def clear_documents(): async def clear_documents():
""" """
@@ -766,7 +771,7 @@ def create_document_routes(
from the input directory. from the input directory.
Returns: Returns:
InsertResponse: A response object containing the status and message. ClearDocumentsResponse: A response object containing the status and message.
- status="success": All documents and files were successfully cleared. - status="success": All documents and files were successfully cleared.
- status="partial_success": Document clear job exit with some errors. - status="partial_success": Document clear job exit with some errors.
- status="busy": Operation could not be completed because the pipeline is busy. - status="busy": Operation could not be completed because the pipeline is busy.
@@ -787,7 +792,7 @@ def create_document_routes(
# Check and set status with lock # Check and set status with lock
async with pipeline_status_lock: async with pipeline_status_lock:
if pipeline_status.get("busy", False): if pipeline_status.get("busy", False):
return InsertResponse( return ClearDocumentsResponse(
status="busy", status="busy",
message="Cannot clear documents while pipeline is busy" message="Cannot clear documents while pipeline is busy"
) )
@@ -855,7 +860,7 @@ def create_document_routes(
logger.error(error_message) logger.error(error_message)
if "history_messages" in pipeline_status: if "history_messages" in pipeline_status:
pipeline_status["history_messages"].append(error_message) pipeline_status["history_messages"].append(error_message)
return InsertResponse( return ClearDocumentsResponse(
status="fail", status="fail",
message=error_message message=error_message
) )
@@ -904,7 +909,7 @@ def create_document_routes(
pipeline_status["history_messages"].append(final_message) pipeline_status["history_messages"].append(final_message)
# Return response based on results # Return response based on results
return InsertResponse( return ClearDocumentsResponse(
status=status, status=status,
message=final_message message=final_message
) )