Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/35 task api implement event zone search with venue management #36

Open
wants to merge 4 commits into
base: development
Choose a base branch
from

Conversation

Morais-C
Copy link
Contributor

Event Zone Search Implementation

Overview

Implementation of geospatial search functionality for live music events, including venue management, location-based queries, and distance calculations.

Changes Made

1. Basic Venue Management

  • Added Venue model with basic fields (name, description, address)
  • Implemented JSON fields for contact info and coordinates
  • Created complete CRUD operations for venues
  • Added validation using Zod schemas
  • Added seed data for testing

2. Geospatial Capabilities

  • Added coordinates field to venues (lat/lng)
  • Implemented coordinate validation (-90/90 lat, -180/180 lng)
  • Added GeoJSON response format
  • Created dedicated GeoJSON endpoints for venues
  • Added coordinate type safety

3. Event-Venue Integration

  • Updated Event model with venue relationship
  • Added foreign key constraints
  • Enhanced event responses with venue data
  • Added venue validation in event creation
  • Created GeoJSON endpoint for events

4. Zone Search Implementation

  • Added zone search endpoint (/api/events/zone)
  • Implemented Haversine formula for distance calculations
  • Added search radius validation (max 50km)
  • Created comprehensive test data:
    • 6 venues in New York (20km radius)
    • 5 venues in Paris (15km radius)
    • 4 venues in Berlin (10km radius)
  • Added filtering by date and status

Technical Details

  • JavaScript-based distance calculations
  • GeoJSON standard compliance
  • Proper coordinate order (lng/lat in GeoJSON)
  • Type safety throughout
  • Efficient data querying

Testing Instructions

  1. Run migrations (ONLY ON LOCAL SQLITE ENVIRONMENT):

    npx prisma migrate reset
  2. Start the server:

    npm run dev
  3. Test zone search:

    GET /api/events/zone?lat=40.7580&lng=-73.9855&radius=20
    
  4. See zone-search-testing.md for detailed test scenarios

Documentation

  • Updated API documentation in Postman
  • Added zone search testing guide
  • Updated schema documentation
  • Added GeoJSON format examples

Technical Decisions

  • Used JSON fields instead of PostGIS for Render compatibility
  • Implemented distance calculations in JavaScript
  • Maintained consistent coordinate formats
  • Added proper validation and error handling

Future Considerations

  • Potential PostGIS migration path
  • Performance optimization for larger datasets
  • Additional spatial query features
  • Index optimization

- Add Venue model to Prisma schema with basic fields
  - name, description, address
  - contact info as JSON (phone, email, website)
  - images array for venue photos
  - timestamps

- Implement complete CRUD operations for venues
  - Create venue with validation
  - Read venue(s) with pagination/sorting
  - Update venue with partial fields
  - Delete venue with proper error handling

- Add validation using Zod schemas
  - Input validation for all fields
  - Query parameter validation
  - Contact info structure validation

- Create venue API endpoints
  - GET /api/venues
  - GET /api/venues/:id
  - POST /api/venues
  - PATCH /api/venues/:id
  - PUT /api/venues/:id
  - DELETE /api/venues/:id

- Add test data
  - Seed three example venues
  - Include realistic contact info
  - Add sample image URLs

- Update documentation
  - Add venue endpoints to Postman collection
  - Document request/response formats
  - Include example payloads

Part of Event Zone Search feature - Step 1/4
- Add coordinates field to Venue model
  - Store as JSON with lat/lng structure
  - Add validation for coordinate ranges
  - Update seed data with real venue coordinates

- Implement GeoJSON support
  - Add GeoJSON types and interfaces
  - Create new /venues/:id/geojson endpoint
  - Convert lat/lng to GeoJSON [longitude, latitude] format
  - Include venue properties in GeoJSON response

- Update documentation
  - Add coordinate validation rules
  - Document GeoJSON endpoint
  - Add example responses in both formats
  - Update Postman collection with new endpoint

- Technical decisions
  - Store coordinates as JSON for Render compatibility
  - Document future migration path to PostGIS
  - Implement proper coordinate validation
  - Follow GeoJSON specification

Part of Event Zone Search feature - Step 2/4
- Update Event model with venue relationship
  - Add venueId field (required)
  - Create foreign key constraint
  - Remove redundant location field
  - Add venue relation field

- Enhance Event responses
  - Include venue details in responses
  - Add GeoJSON endpoint for events
  - Handle missing venue cases
  - Maintain consistent coordinate format

- Update validation and types
  - Add venueId validation
  - Create EventGeoJSONFeature type
  - Update EventResponse type with venue
  - Add proper type casting

- Update documentation
  - Add GeoJSON endpoint examples
  - Document venue relationship
  - Update Postman collection
  - Add error scenarios

Technical notes:
- Use conditional chaining for optional venue data
- Follow GeoJSON specification
- Maintain consistent coordinate order (lng/lat)
- Handle venue not found errors

Part of Event Zone Search feature - Step 3/4
- Add zone search endpoint
  - GET /api/events/zone with lat/lng/radius parameters
  - Optional filters for startDate and status
  - Return events sorted by distance
  - Include search center and radius in response

- Implement geospatial features
  - Add Haversine formula for distance calculations
  - Sort results by distance from center
  - Round distances to 2 decimal places
  - Handle coordinate transformations

- Create realistic test data
  - Add 6 venues in New York (20km radius)
  - Add 5 venues in Paris (15km radius)
  - Add 4 venues in Berlin (10km radius)
  - Add 2-3 events per venue
  - Use real-world coordinates

- Update documentation
  - Create zone-search-testing.md guide
  - Document coordinate formats
  - Add example requests for each city
  - Include test scenarios

Technical notes:
- JavaScript-based distance calculations
- GeoJSON FeatureCollection response format
- Coordinate validation (-90/90 lat, -180/180 lng)
- Maximum radius of 50km

Part of Event Zone Search feature - Step 4/4
@Morais-C Morais-C linked an issue Nov 15, 2024 that may be closed by this pull request
6 tasks
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.

task: (API) Implement Event Zone Search with Venue Management
2 participants