Skip to content

Commit

Permalink
Fixed an issue with the maps API
Browse files Browse the repository at this point in the history
  • Loading branch information
niconoe committed Nov 7, 2024
1 parent 09a5f6c commit 67f3306
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Current (unreleased)

- Fixed a bg with the maps API (see https://github.com/riparias/gbif-alert/issues/283)

# v1.7.6 (2024-07-26)

- Another map performance improvement (missing index)
Expand Down
15 changes: 15 additions & 0 deletions dashboard/tests/views/test_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@ def setUpTestData(cls):
class MinMaxPerHexagonTests(MapsTestDataMixin, TestCase):
"""Tests covering the min_max_in_hexagon endpoint"""

def test_min_max_status_area_combinations(self):
"""Regression test for https://github.com/riparias/gbif-alert/issues/283"""
self.client.login(username="frusciante", password="12345")

response = self.client.get(
reverse("dashboard:internal-api:maps:mvt-min-max-per-hexagon"),
data={
"zoom": 8,
"status": "seen",
"areaIds[]": self.public_area_andenne.pk,
},
)

self.assertEqual(response.status_code, 200)

def test_min_max_per_hexagon(self):
# At zoom level 8, with the initial data: we should have two polygons, both at 1. So min=1 and max=1
response = self.client.get(
Expand Down
6 changes: 5 additions & 1 deletion dashboard/views/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,11 @@ def observation_min_max_in_hex_grid_json(request: HttpRequest):
LEFT JOIN dashboard_species as species ON obs.species_id = species.id
{% if area_ids %}
,(SELECT mpoly FROM $areas_table_name WHERE $areas_table_name.id IN {{ area_ids | inclause }}) AS areas
LEFT JOIN (
SELECT mpoly
FROM $areas_table_name
WHERE $areas_table_name.id IN {{ area_ids | inclause }}
) AS areas ON ST_Within(obs.location, areas.mpoly)
{% endif %}
{% if status == 'seen' %}
INNER JOIN $observationview_table_name
Expand Down

0 comments on commit 67f3306

Please sign in to comment.