Skip to content

feat: add /api/map/neighbors/{familyId} endpoint#8134

Merged
DawoudIO merged 6 commits intomasterfrom
replace-geoutils-phpgeo
Mar 3, 2026
Merged

feat: add /api/map/neighbors/{familyId} endpoint#8134
DawoudIO merged 6 commits intomasterfrom
replace-geoutils-phpgeo

Conversation

@DawoudIO
Copy link
Contributor

@DawoudIO DawoudIO commented Mar 3, 2026

What changed

  • Add GET /api/map/neighbors/{familyId} endpoint using FamilyMiddleware for family lookup and validation
  • Pre-filter candidate families with a lat/lng bounding box query before per-record distance calculation in PHP (avoids full table scan)
  • Use existing GeoUtils for distance and bearing — drops the undeclared mjaschen/phpgeo dependency (not in composer.json/lock; Spherical Law of Cosines is accurate enough for finding church neighbors)
  • Fix OpenAPI annotation: correct path template, familyId as in=path, valid @OA\Get() syntax
  • Use renderErrorJSON + gettext() for error responses (consistent with other routes)
  • Update agent skill docs: document FamilyMiddleware pattern for routes with familyId

Testing

Ensure demo DB is loaded, then run the Cypress spec or call the endpoint directly:

GET /api/map/neighbors/{familyId}?maxNeighbors=5&maxDistance=50

Cypress spec: cypress/e2e/api/private/map-neighbors.spec.js

Copilot AI review requested due to automatic review settings March 3, 2026 15:51
@DawoudIO DawoudIO requested a review from a team as a code owner March 3, 2026 15:51
@DawoudIO DawoudIO requested review from DAcodedBEAT, MrClever, bigtigerku, grayeul and respencer and removed request for a team March 3, 2026 15:51
@DawoudIO DawoudIO added this to the 7.0.1 milestone Mar 3, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new Map API capability to fetch “neighbor” families by distance, leveraging mjaschen/phpgeo (Vincenty) for distance calculation while keeping legacy geodesy helpers as fallback/for display.

Changes:

  • Add GET /api/map/neighbors/{familyId} endpoint (with FamilyMiddleware) to return nearby families, distances, bearings, and household members.
  • Add a Cypress API spec to validate the new endpoint behavior against seeded demo data.
  • Update Slim MVC skill docs to document the FamilyMiddleware pattern for routes with familyId.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.

File Description
src/api/routes/map.php Adds the new /map/neighbors/{familyId} endpoint and OpenAPI annotations.
cypress/e2e/api/map-neighbors.spec.js Adds an API test for the neighbors endpoint using an admin API key.
.agents/skills/churchcrm/slim-mvc-skill.md Documents using FamilyMiddleware for routes that accept familyId.

- Add GET /map/neighbors/{familyId} using FamilyMiddleware for family
  lookup/validation; returns nearby families sorted by distance
- Pre-filter candidates with a lat/lng bounding box query before
  per-record distance calculation (avoids full table scan)
- Use GeoUtils for distance and bearing (drops undeclared phpgeo dep)
- Fix OA annotation: correct path, familyId as in=path, valid syntax
- Use renderErrorJSON + gettext for error responses
- Move Cypress spec to cypress/e2e/api/private/; use
  makePrivateAdminAPICall helper; assert all response fields

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@DawoudIO DawoudIO changed the title feat: replace GeoUtils with phpgeo; add /api/map/neighbors feat: add /api/map/neighbors/{familyId} endpoint Mar 3, 2026
@DawoudIO DawoudIO merged commit b2791b6 into master Mar 3, 2026
13 checks passed
@DawoudIO DawoudIO deleted the replace-geoutils-phpgeo branch March 3, 2026 17:23
@github-actions github-actions bot mentioned this pull request Mar 3, 2026
DawoudIO pushed a commit that referenced this pull request Mar 3, 2026
This PR updates the locale translation strings extracted from source
code.

## Triggered By
Commit: `b2791b6a055a1106d96d461cbb9a22e1059e4087`
Message: feat: add /api/map/neighbors/{familyId} endpoint (#8134)

## What changed

- Add `GET /api/map/neighbors/{familyId}` endpoint using
`FamilyMiddleware` for family lookup and validation
- Pre-filter candidate families with a lat/lng bounding box query before
per-record distance calculation in PHP (avoids full table scan)
- Use existing `GeoUtils` for distance and bearing — drops the
undeclared `mjaschen/phpgeo` dependency (not in composer.json/lock;
Spherical Law of Cosines is accurate enough for finding church
neighbors)
- Fix OpenAPI annotation: correct path template, `familyId` as
`in=path`, valid `@OA\Get()` syntax
- Use `renderErrorJSON` + `gettext()` for error responses (consistent
with other routes)
- Update agent skill docs: document `FamilyMiddleware` pattern for
routes with `familyId`

## Testing

Ensure demo DB is loaded, then run the Cypress spec or call the endpoint
directly:

```
GET /api/map/neighbors/{familyId}?maxNeighbors=5&maxDistance=50
```

Cypress spec: `cypress/e2e/api/private/map-neighbors.spec.js`

## Changes
- Updated `locale/terms/messages.po` with new/modified translatable
strings
- Updated JSON locale keys

## Next Steps
- Review the new strings that need translation
- Merge this PR to update the base locale file
- Upload to POEditor for translation if needed

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants