Docs
Routes
Document.routes

Document Routes

routes.document_routes.delete_document()

Deletes a document from the database using the specified file ID.

URL:

  • POST /document/delete
  • Parameters: file_id (str) – The ID of the document to be deleted.
  • Returns: A message indicating the deletion status along with details of the deleted document or an error message.
  • Return type: JSON response (dict)

Status Codes:

  • 200 OK: Document deleted successfully.
  • 400 Bad Request: An error occurred.

Access Control:

  • Requires at least one of the following roles: Admin, Master, Worker

routes.document_routes.get_document_content()

Retrieves the content of a document based on its file ID. This function uses the get_file method to fetch the document from the database and then extracts the text using PyMuPDF or docx depending on the file type.

URL:

  • POST /document/get_content
  • Parameters: file_id (str) – The ID of the document to retrieve.
  • Returns: The retrieved document content in plain text or an error message.
  • Return type: JSON response (dict)

Status Codes:

  • 200 OK: Document content retrieved successfully.
  • 400 Bad Request: Invalid payload or an error occurred.

Access Control:

  • Requires at least one of the following roles: Admin, Master, Worker

routes.document_routes.get_documents()

Retrieves all documents from the database.

URL:

  • POST /document/get_all
  • Returns: A list of all documents or an error message.
  • Return type: JSON response (dict)

Status Codes:

  • 200 OK: Documents retrieved successfully.
  • 400 Bad Request: An error occurred.

Access Control:

  • Requires at least one of the following roles: Admin, Master, Worker

routes.document_routes.upload_document()

Uploads one or more documents to the database.

URL:

  • POST /document/upload
  • Parameters: files (list of FileStorage) – The files to be uploaded.
  • Returns: Details of the uploaded documents along with a status message or an error message.
  • Return type: JSON response (dict)

Status Codes:

  • 200 OK: Document uploaded successfully. 400 Bad Request: Invalid request payload or an error occurred.

Access Control:

  • Requires one of the following roles: Admin, Master, Worker