Skip to content

Add Vancouver City API Integration for Facility Import#221

Merged
fabionl merged 24 commits into
developfrom
FL-VancouverApiClient
Jul 1, 2025
Merged

Add Vancouver City API Integration for Facility Import#221
fabionl merged 24 commits into
developfrom
FL-VancouverApiClient

Conversation

@fabionl
Copy link
Copy Markdown
Collaborator

@fabionl fabionl commented Jul 1, 2025

What this does

Adds the ability for admins to import drinking fountain facilities from Vancouver City's Open Data API directly through the admin interface.

Key Business Logic

Import Process:

  1. Admin selects Vancouver City API from dropdown in admin tools
  2. System fetches all drinking fountain data from Vancouver's Open Data API
  3. Each facility is processed and saved with service: water_fountain
  4. Imported facilities are automatically marked as verified: true
  5. System tracks external records using new external_id field to prevent duplicates

Data Mapping:

  • Vancouver drinking fountain locations → LinkVan water fountain facilities
  • Facility schedules set to 24/7 availability (API has no operating hours data)
  • Accessibility info → facility welcome messages
  • Geographic coordinates preserved as-is

Create/Update Logic:

  • External facilities (have external_id): Matched by external_id, updates facility data and adds water_fountain service
  • Internal facilities (no external_id): Matched by name, only adds water_fountain service (preserves manual data)
  • New facilities: Creates new facility with external_id and water_fountain service

Key Decisions & Assumptions

  • Service mapping: Vancouver drinking fountains are imported as 'water_fountain' service in our system
  • Default schedules: All imported fountains set to open 24/7 since API provides no operating hours
  • Auto-verification: All imported facilities are trusted and marked verified
  • Data preservation: Internal facilities matched by name keep their existing data, only gain new services
  • Admin-only: Import functionality restricted to admin users for data integrity
  • Batch processing: Imports all available records in single operation
  • Error handling: Failed imports redirect back to tools with error message, successful imports redirect to facilities filtered by water_fountain

Database Changes

  • Added external_id field to facilities table for tracking imported records

fabionl added 24 commits June 28, 2025 14:01
… API

- Implement VancouverApiClient for interacting with the Vancouver Open Data API.
- Create VancouverApiConfig for configuration management including base URL and timeouts.
- Add FaradayAdapter for HTTP requests with customizable options.
- Implement dataset retrieval methods: get_dataset, get_datasets, get_dataset_records, and get_dataset_record.
- Introduce error handling with custom VancouverApiError class for better error reporting.
- Add comprehensive RSpec tests for client creation, dataset APIs, error handling, and request structure.
- Include shared helpers for mocking responses in tests.
- Implement integration scenarios for comprehensive and minimal facility data.
- Add edge case tests for special characters and edge coordinates.
- Simulate concurrent operations and verify data consistency.
- Create internal update operation tests to handle service synchronization.
- Introduce operation detection tests to determine create, external_update, and internal_update operations.
- Ensure result structure compliance with ApplicationService::Result.
- Validate service synchronization logic for adding and maintaining services.
- Handle edge cases for service creation and duplication gracefully.
@fabionl fabionl merged commit 67695ba into develop Jul 1, 2025
2 checks passed
@fabionl fabionl deleted the FL-VancouverApiClient branch July 1, 2025 20:21
fabionl added a commit that referenced this pull request Jul 1, 2025
* Add local port mapping for Postgres and enhance logging in data rake task

* Fix migrations (#219)

* Add local port mapping for Postgres and enhance logging in data rake task

* Fix facility suitability migration

(cherry picked from commit e82d4f4)

* Fix Puma configuration to disable workers in development and ensure proper preloading

* Fix facilities fake data generation

* Fix admin root route to point directly to the dashboard controller

* Fix ChangeAllSuitabilityPermutations migration

* Fix migration to use MigrationFacility class for updating welcomes

(cherry picked from commit 4ffe866)

* Fix migration to use MigrationFacility class for updating zone references

(cherry picked from commit 7527626)

* Fix migration to use MigrationFacility class for importing facility schedules

(cherry picked from commit f8bd94a)

* Add Vancouver City API Integration for Facility Import (#221)

* Update database configuration to use environment variable for test database URL

* Add VancouverApiClient and supporting classes for Vancouver Open Data API

- Implement VancouverApiClient for interacting with the Vancouver Open Data API.
- Create VancouverApiConfig for configuration management including base URL and timeouts.
- Add FaradayAdapter for HTTP requests with customizable options.
- Implement dataset retrieval methods: get_dataset, get_datasets, get_dataset_records, and get_dataset_record.
- Introduce error handling with custom VancouverApiError class for better error reporting.
- Add comprehensive RSpec tests for client creation, dataset APIs, error handling, and request structure.
- Include shared helpers for mocking responses in tests.

* Fix indentation for form_with in facilities index view

* Refactor services structure for external services.

* Refactor API handling in ToolsController and add External::ApiHelper for better API management

* cleanup

* Refactor FacilityBuilder

* Update facility verification status to true for new imports

* Add external_id field to Facility model and update FacilityBuilder to assign it

* Refactor FacilityBuilder to streamline facility data extraction and ensure verified status is set to true

* Fix facility building spec

* Refactor FacilityBuilder geometry validation and update specs to check external_id assignment

* Rename LIMIT to PAGE_SIZE for consistency in Syncer class and update related logging and API call references

* Add integration and unit tests for Vancouver City FacilitySyncer

- Implement integration scenarios for comprehensive and minimal facility data.
- Add edge case tests for special characters and edge coordinates.
- Simulate concurrent operations and verify data consistency.
- Create internal update operation tests to handle service synchronization.
- Introduce operation detection tests to determine create, external_update, and internal_update operations.
- Ensure result structure compliance with ApplicationService::Result.
- Validate service synchronization logic for adding and maintaining services.
- Handle edge cases for service creation and duplication gracefully.

* Refactor ResultData structure in FacilityBuilder and FacilitySyncer for consistency and update related specs

* Add progress indicator and loading state for facility import form

* Add service key mapping and update related specs for Vancouver City API integration

* Add API key validation and remove redundant tests in FacilityServiceBuilder and FacilitySyncer

* Update service parameter naming in facilities index

* Fix redirect path for successful facility import in ToolsController

* Fix FacilitySyncer specs
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