Add POST /export/batch endpoint for multi-company ZIP download #1689

Open
AI-Manager wants to merge 1 commits from feature/1674-batch-export-zip into main
Owner

Summary

  • Adds a new authenticated POST /export/batch endpoint that accepts a list of company names and an optional format (csv or pdf)
  • Compiles per-company exports into a ZIP archive using Python's zipfile module and returns a streaming application/zip response with Content-Disposition: attachment; filename=sparc-export-<date>.zip
  • Extracts _fetch_company_rows, _build_company_csv, and _build_company_pdf helpers so both the new batch endpoint and the existing single-company endpoints share the same logic (no duplication)
  • Companies with no stored analysis data are skipped gracefully; a manifest.json inside every ZIP lists exported and skipped companies

Test plan

  • TestBatchExportAuth — unauthenticated and invalid-token requests return 401
  • TestBatchExportSingleCompany — single company CSV/PDF, valid ZIP structure, correct CSV header/content, PDF magic bytes
  • TestBatchExportMultipleCompanies — each company gets its own file, manifest lists all exported, partial-missing companies are skipped
  • TestBatchExportAllMissing — all-skipped scenario returns 200 with manifest-only ZIP
  • TestBatchExportManifest — manifest always present, contains required keys, format field matches request
  • TestBatchExportInputValidation — invalid format returns 422, empty list returns 422, default format is csv
  • All 13 existing test_export.py tests still pass after the refactor

Closes leeworks-agents/SPARC#1674

## Summary - Adds a new authenticated `POST /export/batch` endpoint that accepts a list of company names and an optional `format` (`csv` or `pdf`) - Compiles per-company exports into a ZIP archive using Python's `zipfile` module and returns a streaming `application/zip` response with `Content-Disposition: attachment; filename=sparc-export-<date>.zip` - Extracts `_fetch_company_rows`, `_build_company_csv`, and `_build_company_pdf` helpers so both the new batch endpoint and the existing single-company endpoints share the same logic (no duplication) - Companies with no stored analysis data are skipped gracefully; a `manifest.json` inside every ZIP lists `exported` and `skipped` companies ## Test plan - [x] `TestBatchExportAuth` — unauthenticated and invalid-token requests return 401 - [x] `TestBatchExportSingleCompany` — single company CSV/PDF, valid ZIP structure, correct CSV header/content, PDF magic bytes - [x] `TestBatchExportMultipleCompanies` — each company gets its own file, manifest lists all exported, partial-missing companies are skipped - [x] `TestBatchExportAllMissing` — all-skipped scenario returns 200 with manifest-only ZIP - [x] `TestBatchExportManifest` — manifest always present, contains required keys, format field matches request - [x] `TestBatchExportInputValidation` — invalid format returns 422, empty list returns 422, default format is csv - [x] All 13 existing `test_export.py` tests still pass after the refactor Closes leeworks-agents/SPARC#1674
AI-Manager added 1 commit 2026-05-19 15:25:42 +00:00
Implements issue #1674: a new authenticated POST /export/batch endpoint
that accepts a list of company names and an optional format (csv or pdf),
compiles per-company exports into a ZIP archive using Python's zipfile
module, and returns it as a streaming download.

Key changes:
- Extract `_fetch_company_rows`, `_build_company_csv`, `_build_company_pdf`
  helpers to eliminate duplication between the single-company endpoints and
  the new batch endpoint
- Refactor `export_company_csv` and `export_company_pdf` to delegate to the
  new helpers
- Add `BatchExportRequest` Pydantic model (companies list + format field)
- Add `POST /export/batch` which iterates over companies, skips those with
  no data, writes per-company files into the ZIP, and always includes a
  `manifest.json` listing exported and skipped companies
- Response header: `Content-Disposition: attachment; filename=sparc-export-<date>.zip`
- 17 new tests covering: single company (CSV + PDF), multiple companies,
  all-missing, unauthenticated, invalid-token, manifest structure, input
  validation

Closes leeworks-agents/SPARC#1674

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feature/1674-batch-export-zip:feature/1674-batch-export-zip
git checkout feature/1674-batch-export-zip
Sign in to join this conversation.