feat: Add city filtering to bicycle-racks API - #7
Open
dvalenca wants to merge 18 commits into
Open
Conversation
…Pernambuco, Brasil.geojson,
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🚀 Overview
Enhanced the bicycle-racks API with optional city filtering capability, allowing users to query data for specific cities or retrieve all data from Brazil.
🔧 Changes Made
Database Schema
Added bicycle_rack_cities table to map OSM IDs to cities for efficient filtering
Updated seed process to populate city mappings from Recife-specific GeoJSON data
Added conflict handling with onConflictDoNothing() for duplicate OSM IDs
API Enhancements
Added optional city parameter to all bicycle-racks endpoints:
GET /v1/bicycle-racks?city=Recife
GET /v1/bicycle-racks/geojson?city=Recife
GET /v1/bicycle-racks/stats?city=Recife
GET /v1/bicycle-racks/nearby?city=Recife&lat=-8.0631&lng=-34.8713&radius=1000
Performance Optimization
JOIN-based filtering instead of PostGIS radius queries for better performance
Efficient hash join strategy executing in ~1.7ms for city-specific queries
📊 Data Results
Total Brazil: 5,598 bicycle racks
Recife only: 578 bicycle racks (when city=Recife)
Performance: Fast queries using indexed JOIN operations
🧪 Testing
Added comprehensive SQL test queries (41 total) to validate:
City filtering functionality
Data quality analysis
Performance benchmarking
Capacity anomaly investigation
🔄 API Flexibility
Without city parameter: Returns all Brazil data
With city=Recife: Returns only Recife data
Extensible: Ready for additional cities as data becomes available
✅ Validation
All endpoints tested with curl and confirmed working:
Stats: 5,598 total → 578 for Recife
GeoJSON: 5,598 features → 578 for Recife
Nearby: Location-based filtering within city boundaries