Skip to content

Conversation

SakshiKekre
Copy link
Collaborator

Summary

Implemented report API functionality with corrected ID handling and proper alignment between frontend types and backend API endpoints.

TODO: API for calculation endpoint

Key Changes

Type Alignment Fixes

  • Fixed ID handling: Updated ReportMetadata to use id instead of report_id (matches backend auto-increment pattern)
  • Made Report fields optional: reportId, createdAt, updatedAt now optional like Policy type (populated after creation)
  • Simplified creation payload: ReportCreationPayload now only includes simulation_1_id and simulation_2_id (backend generates ID/timestamps)
  • Streamlined update payload: Removed redundant fields from ReportSetOutputPayload (report ID passed in URL path)

New API Functions

  • fetchReportById(countryId, reportId) - GET report by ID
  • createReport(countryId, payload) - POST new report (creates with 'pending' status)
  • updateReport(countryId, reportId, payload) - PATCH report status/output

Updated Adapters

  • ReportAdapter.fromMetadata() - Fixed ID mapping (id → reportId)
  • ReportAdapter.toCreationPayload() - Simplified to only send simulation IDs
  • ReportAdapter.toCompletedReportPayload() - Streamlined for status updates
  • ReportAdapter.toErrorReportPayload() - Added error state handling

Testing

  • Updated all existing report adapter tests (12 passing)
  • Added comprehensive report API tests (6 passing)
  • Fixed mock data to match corrected types
  • Total: 18 tests passing

Copy link
Collaborator

@anth-volk anth-volk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work on this @SakshiKekre! There are a few points where I'd recommend changes (basically only around using conversion adapters) and a couple questions, otherwise we'll be good to go.

Copy link
Collaborator

@anth-volk anth-volk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a few requested changes, plus I believe a couple comments remain incomplete.

@SakshiKekre
Copy link
Collaborator Author

SakshiKekre commented Sep 13, 2025

issue: I should've paid more attention previously, but here, too, passing reportId as a URL param instead of in the body is pretty uncommon. Would recommend moving to body.

Thanks for pointing this out in all spots where ID is used. It’s helpful because I don’t have to dig through each line myself. Mentioning my thoughts here for all comments relevant to ID in the URL:

While I agree that URLs for PATCH shouldn’t include path parameters where possible, in this case, the reportId is an identifier, not part of the patch data itself to go in the body. The path identifies which resource is being updated, while the body describes what is updated.

This aligns with common REST conventions:

  • GET /report/{id} fetches a report
  • PATCH /report/{id} updates a report
  • DELETE /report/{id} deletes a report

Removing the ID from the path would make the PATCH act on the collection (/report), which is less canonical and inconsistent with the rest of the CRUD model.

Given that, I’d prefer to keep the reportId in the path across these occurrences.

BTW, this also makes me want to rename the endpoints from report -> reports and simulation -> simulations to better reflect collections.

@anth-volk anth-volk force-pushed the feat/report-simulations-api branch from 56a88a7 to 4a56931 Compare September 13, 2025 20:57
@anth-volk anth-volk marked this pull request as draft September 13, 2025 20:58
@anth-volk
Copy link
Collaborator

Note: DO NOT MERGE until API update (https://github.com/PolicyEngine/policyengine-api/actions/runs/17701223907/attempts/1) is fully deployed

SakshiKekre and others added 12 commits September 14, 2025 16:57
- Fix ReportMetadata to use 'id' instead of 'report_id' (matches backend auto-increment)
- Make Report.reportId optional like Policy.id (populated after creation)
- Simplify ReportCreationPayload to only include simulation IDs (backend generates ID/timestamps)
- Update ReportSetOutputPayload to remove redundant fields (ID in URL path)
- Update ReportAdapter to handle proper ID mapping and simplified payloads
- Add report API functions: fetchReportById, createReport, updateReport
- Fix all tests and mocks to match corrected types
- All report adapter and API tests passing (18 total)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Fix type misalignments between frontend and backend API
- Implement CRUD operations: fetchReportById, createReport, updateReport
- Add comprehensive test coverage (18 tests: 12 adapter + 6 API)
- Align ID handling with database auto-increment pattern
- Simplify creation payloads to only required fields

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@anth-volk anth-volk force-pushed the feat/report-simulations-api branch from 4a56931 to c0950a3 Compare September 14, 2025 15:57
@anth-volk anth-volk marked this pull request as ready for review September 14, 2025 16:21
@anth-volk anth-volk merged commit efe7a1d into main Sep 14, 2025
4 checks passed
@anth-volk anth-volk deleted the feat/report-simulations-api branch September 14, 2025 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants