add center and radius params

This commit is contained in:
Matteo Rosati
2026-01-18 11:41:55 +01:00
parent 6cd8997516
commit de53b760c4
2 changed files with 177 additions and 11 deletions

View File

@@ -401,6 +401,81 @@ curl "http://localhost:7000/plexts?min_timestamp=2026-01-12T10:00:00Z&max_timest
curl "http://localhost:7000/plexts?event_types=PORTAL_CAPTURED&player_name=Albicocca&min_timestamp=2026-01-12T10:00:00Z"
```
##### GET /plexts/from-db
Get plexts from MongoDB with optional filters. Returns plexts sorted by timestamp (most recent first).
**Query Parameters:**
| Parameter | Type | Default | Description |
| --------------- | ------- | -------- | --------------------------------------------------- |
| `player_name` | String | None | Player name to filter by |
| `timestamp_from` | Integer | None | Minimum timestamp in milliseconds (optional) |
| `timestamp_to` | Integer | None | Maximum timestamp in milliseconds (optional) |
| `limit` | Integer | 100 | Maximum number of results to return |
| `center` | String | None | Geographic center point in format "latitude,longitude" (optional, requires radius) |
| `radius` | Integer | None | Search radius in meters (optional, requires center) |
**Geospatial Query:**
When both `center` and `radius` parameters are provided, the endpoint returns plexts within the specified radius from the center point. The response includes a `distance` field (in meters) for each result.
**Response with geospatial query:**
```json
{
"count": 5,
"plexts": [
{
"id": "abc123",
"timestamp": 1736659207000,
"timestamp_formatted": "2026-01-12 11:00:07",
"text": "Albicocca captured L' Arboreto",
"team": "RESISTANCE",
"plext_type": "PLAYER_GENERATED",
"categories": 0,
"event_type": "PORTAL_CAPTURED",
"player_name": "Albicocca",
"portal_name": "L' Arboreto",
"coordinates": {
"type": "Point",
"coordinates": [12.365208, 45.573661]
},
"distance": 125.5,
"markup": [...]
}
]
}
```
**Note:** Both `center` and `radius` parameters must be provided together. If neither is provided, the endpoint returns all plexts matching other filters without geospatial filtering.
**Examples:**
```bash
# Get all plexts from MongoDB
curl "http://localhost:7000/plexts/from-db"
# Filter by player name
curl "http://localhost:7000/plexts/from-db?player_name=Albicocca"
# Filter by time range
curl "http://localhost:7000/plexts/from-db?timestamp_from=17366592000000&timestamp_to=1736745600000"
# Geospatial query: Get plexts within 1km of a specific location
curl "http://localhost:7000/plexts/from-db?center=45.573661,12.365208&radius=1000"
# Geospatial query with player filter
curl "http://localhost:7000/plexts/from-db?center=45.573661,12.365208&radius=1000&player_name=Albicocca"
# Geospatial query with time filter
curl "http://localhost:7000/plexts/from-db?center=45.573661,12.365208&radius=1000&timestamp_from=17366592000000"
# Combine all filters
curl "http://localhost:7000/plexts/from-db?center=45.573661,12.365208&radius=1000&player_name=Albicocca&timestamp_from=17366592000000&limit=10"
```
**Authentication:** Basic Auth required
### Scheduler
The scheduler automatically collects Ingress events every minute and stores them in MongoDB.