Skip to content

Add Run Matching admin page - #155

Open
Khai189 wants to merge 3 commits into
mainfrom
feature/run-matching-commit
Open

Khai189 wants to merge 3 commits into
mainfrom
feature/run-matching-commit

Conversation

@Khai189

@Khai189 Khai189 commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Context

Adds the admin UI for running the ride-matching algorithm. The algorithm runs as its own AWS Lambda function (Function URL), separate from this Netlify app. This PR only adds the frontend page and the server-side routes that call it; the Lambda's code and deploy steps live outside this repo.

This replaces the earlier plan of running the service behind the aspc-website-v2 backend (aspc/aspc-website-v2#254, now closed).

Admin → /admin/matching → /api/admin/matching/{status,run} (Netlify, admin-only)
                                   │ X-API-Key
                                   ▼
                        AWS Lambda (matching) → Supabase

Describe your changes

  • frontend/src/app/admin/matching/page.tsx: new /admin/matching route, behind the existing admin auth layout.
  • frontend/src/components/admin/MatchingAlgorithm.tsx: "Run Matching" UI. Pulls riders from the database and commits the result through the Lambda's /run endpoint, which writes groups and matches to Supabase and consumes vouchers. Shows a confirmation dialog first, since a run can't be undone or previewed from here.
  • frontend/src/app/api/admin/matching/run/route.ts and .../status/route.ts: server-only routes. The browser never talks to the Lambda directly; these call ALGORITHM_SERVICE_URL with ALGORITHM_SERVICE_API_KEY.
  • Subsidized dates come from this app: /run sends subsidized_periods, built from SERVICE_PERIODS by the new getSubsidizedPeriodRanges() in servicePeriodHelpers.ts. The matcher subsidizes exactly the dates students see on the site, instead of keeping its own hardcoded list, which had drifted and was missing Thanksgiving 2026. Changing break dates now only means editing servicePeriods.ts.
  • frontend/src/components/admin/AdminDashboard.tsx: a "Run Matching Algorithm" button next to "View & Manage Groups".
  • frontend/.env.example: documents the two server-only env vars.

Before this works in prod

  1. Deploy the matching Lambda and create its Function URL.
  2. In Netlify → Site configuration → Environment variables, set:
    • ALGORITHM_SERVICE_URL: the Lambda Function URL
    • ALGORITHM_SERVICE_API_KEY: the same value as the Lambda's SERVICE_API_KEY
  3. Redeploy the site.

Until then, /admin/matching shows a "not configured" banner and nothing runs.

Testing

  • Type/lint/format: tsc --noEmit, eslint, and prettier --check are clean on every changed file.
  • Unit tests: 266/266 Jest tests pass, including new tests for getSubsidizedPeriodRanges(): it matches SERVICE_PERIODS, and every range boundary agrees with isDateCovered.
  • Lambda contract: called the Lambda handler locally with Function URL events:
    • Thanksgiving riders are subsidized when the Thanksgiving range is sent.
    • They aren't when the range is for another break or the other direction.
    • A missing or invalid subsidized_periods is rejected with 422.
    • API-key checks return 401/503 as expected.
  • Not yet tested: a real /run against the deployed Lambda and Supabase.

🤖 Generated with Claude Code

Rebuilt on current main after the frontend/ML monorepo merge — the
original commits were based on the pre-merge root-level layout.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@netlify

netlify Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for p-ickup ready!

Name Link
🔨 Latest commit 66442e1
🔍 Latest deploy log https://app.netlify.com/projects/p-ickup/deploys/6af5325c332437ad3e5037db
😎 Deploy Preview https://deploy-preview-155--p-ickup.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@Khai189
Khai189 requested a balanced review from Copilot October 29, 2026 02:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

Khai189 and others added 2 commits October 28, 2026 19:58
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The matching service now runs as its own AWS Lambda (Function URL)
instead of behind the aspc-website-v2 backend proxy, so .env.example
points ALGORITHM_SERVICE_URL/ALGORITHM_SERVICE_API_KEY at it.

/run now sends subsidized_periods, built from SERVICE_PERIODS by the new
getSubsidizedPeriodRanges() helper, so the matcher subsidizes exactly
the dates students are shown instead of keeping its own hardcoded list
(which had drifted: it was missing Thanksgiving 2026 entirely).

Also strips a trailing slash from ALGORITHM_SERVICE_URL (Function URLs
are shown with one, which made the request path //run) and only passes
string error details through to the UI (FastAPI 422s are lists).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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