Skip to content

feat: add query parameter filtering to all collection endpoints#68

Open
AdityaAsopa wants to merge 2 commits intoisro:masterfrom
AdityaAsopa:feat/query-filtering
Open

feat: add query parameter filtering to all collection endpoints#68
AdityaAsopa wants to merge 2 commits intoisro:masterfrom
AdityaAsopa:feat/query-filtering

Conversation

@AdityaAsopa
Copy link

Summary

Adds URL query parameter filtering to all five collection endpoints, making the API significantly more useful for consumers who need subsets of the data.

New filtering capability

Endpoint Supported filters
/api/spacecrafts status, orbit_type, mission_type, launch_vehicle
/api/launchers vehicle_family
/api/customer_satellites country, launcher
/api/centres state
/api/spacecraft_missions status, orbit_type, mission_type, launch_vehicle, launch_site

Example queries

/api/spacecrafts?status=active
/api/spacecrafts?orbit_type=GEO&status=decommissioned
/api/spacecraft_missions?mission_type=Remote+Sensing&orbit_type=SSO
/api/customer_satellites?country=Germany
/api/launchers?vehicle_family=PSLV
/api/centres?state=Karnataka

Behaviour

  • Case-insensitive?status=Active and ?status=active are equivalent
  • Composable — multiple filters narrow results (AND logic)
  • Unknown params ignored — forward-compatible; adding new fields won't break old clients
  • Empty array, not 404 — when filters match no records, returns { "spacecrafts": [] }

Backward compatibility

Calling any endpoint without query params returns the full collection exactly as before — no breaking changes.

Notes

This PR depends on the normalized data from PR #65. The filter values (GEO, SSO, active, PSLV, etc.) are only consistent and useful because the underlying data has been normalized to use consistent field names and values.

Test plan

  • /api/spacecrafts?status=active returns only active spacecrafts
  • /api/spacecrafts?orbit_type=GEO&status=active returns intersection
  • /api/spacecrafts?status=ACTIVE (uppercase) returns same result
  • /api/spacecrafts?unknown_param=foo returns full collection
  • /api/spacecrafts?status=nonexistent returns { "spacecrafts": [] }
  • All endpoints without params return same response as before

The spacecraft_missions data had deeply inconsistent schemas — mass appeared
as 'weight', 'lift-off_mass', 'spacecraft_mass', 'mass_at_lift-off' and
5 other variants; dates ranged from 'April 19, 1975' to '22 October 2008'
to '26-05-1999' across 15+ formats; KALPANA-1 had mission_life stored in
the 'mission' field as '7 Years'; and TES appeared as a duplicate entry.
spacecrafts.json had only id+name for 113 records. launchers.json had
only id for 81 records. customer_satellites.json mixed 'GERMANY' with
'Germany' and 'UK' with 'UNITED KINGDOM'.

This commit introduces scripts/normalize_data.py — an idempotent pipeline
that parses all date formats to ISO 8601, extracts numeric mass_kg and
power_watts from free-text fields (handling edge cases like '15 Sq.m Solar
Array generating 1360W'), classifies orbits (LEO/SSO/GEO/Lunar/Failed),
infers mission status from launch date + mission life, and normalizes
country names. The scraper was re-run against isro.gov.in and the fresh
data is merged with existing records — no data is lost, only enriched.

All 5 data files now have consistent, documented schemas. spacecrafts are
enriched with launch date, vehicle, orbit type, and status from missions.
Launchers are classified into 8 vehicle families. All API endpoints remain
backward-compatible — same URLs, same structure, just cleaner data.

API handlers: removed unused 'fs' imports, fixed misleading variable names
(customer_satellites.js loaded data into a var called 'launchers'), added
Content-Type: application/json headers, and sanitized error responses.
Root endpoint now returns a JSON directory of all available endpoints.
Each collection endpoint now accepts filter parameters:
- /api/spacecrafts?status=active&orbit_type=GEO&mission_type=Communication&launch_vehicle=PSLV
- /api/launchers?vehicle_family=PSLV
- /api/customer_satellites?country=Germany&launcher=PSLV-C37
- /api/centres?state=Karnataka
- /api/spacecraft_missions?status=active&orbit_type=SSO&mission_type=Remote+Sensing&launch_site=SDSC+SHAR

Filters are case-insensitive and composable — multiple params narrow
results. Unknown params are ignored. Empty array returned (not 404)
when filters match no records. No changes to existing response shape
when called without params.
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.

1 participant