Skip to content

Updated PVForecastForm to match backend API - #289

Open
AdityaShome wants to merge 1 commit into
openclimatefix:mainfrom
AdityaShome:match-backend-api-request
Open

Updated PVForecastForm to match backend API#289
AdityaShome wants to merge 1 commit into
openclimatefix:mainfrom
AdityaShome:match-backend-api-request

Conversation

@AdityaShome

@AdityaShome AdityaShome commented Aug 29, 2025

Copy link
Copy Markdown

Description/ Reason

The frontend request didn’t match the backend API:

  • Called POST /forecast (missing trailing slash) → 404
  • Sent raw form values instead of { site: { ... } } → 422
  • Read data.power_kw instead of data.predictions.power_kw → empty UI

This PR aligns the frontend with the FastAPI schema and the actual response shape so predictions render.

Fixes

  • File: dashboards/dashboard_1/src/components/PVForecastForm.tsx
    • Use POST http://localhost:8000/forecast/ (with trailing slash)
    • Wrap request body as { site: values }
    • Update response handling to data.predictions.power_kw

How Has This Been Tested?

  1. Start backend:
    python api/v0/main.py
  2. Start frontend:
    cd dashboards/dashboard_1
    npm install
    npm run dev
  3. Open the dashboard, submit the Predict form with any values.
  4. Expect predictions to render without console or network errors.

Notes

  • CORS already allows http://localhost:5173 in api/v0/app/main.py.
  • No breaking changes to types or UI; just request/response alignment.

Checklist:

  • My code follows OCF's coding style guidelines
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if applicable
  • I have added tests that prove my fix is effective or that my feature works, (I have not written any test as it is already test, but please mention if I should)
  • I have checked my code and corrected any misspellings

@peterdudfield

Copy link
Copy Markdown
Contributor

Ive now made a new api in V1, do we think we should still merge this?

@AdityaShome

Copy link
Copy Markdown
Author

Thanks, I have checked out api endpoints on the updated repository for both versions. But previous issue remains due to the raw values being sent, instead of the schema the backend expects. I tested with the changes, by wrapping the payload under site which matches the expected schema and backend response nests inside predictions which was missing, so included the field in response schema, fixing the issue.

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