From 20f991443cac88dd58a7aa71e973546b4485b539 Mon Sep 17 00:00:00 2001 From: Jonas Baumann Date: Fri, 6 Sep 2024 21:54:20 +0200 Subject: [PATCH] api: make coordinates ordering consistent. --- api/app/elastic.py | 4 ++-- api/app/server.py | 4 ++-- api/tests/test_elastic.py | 4 ++-- api/tests/test_http.py | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/api/app/elastic.py b/api/app/elastic.py index 0bcfd9d..4d41e52 100644 --- a/api/app/elastic.py +++ b/api/app/elastic.py @@ -18,13 +18,13 @@ def __init__(self) -> None: basic_auth=(settings.elastic_user, settings.elastic_password), ) - def search_documents(self, latitude: float, longitude: float, radius: str) -> list[dict]: + def search_documents(self, longitude: float, latitude: float, radius: str) -> list[dict]: """Search for documents in the index, returning only a list of documents as dicts""" response = self.search( { "bool": { "must": {"match_all": {}}, - "filter": {"geo_distance": {"distance": radius, "coordinates": {"lat": latitude, "lon": longitude}}}, + "filter": {"geo_distance": {"distance": radius, "coordinates": {"lon": longitude, "lat": latitude}}}, } } ) diff --git a/api/app/server.py b/api/app/server.py index 18ba636..9f9d5d2 100644 --- a/api/app/server.py +++ b/api/app/server.py @@ -27,6 +27,6 @@ async def health(): @app.get("/api/photos") -async def photos(latitude: float = Query(...), longitude: float = Query(...), radius: float = Query(...)): +async def photos(longitude: float = Query(...), latitude: float = Query(...), radius: float = Query(...)): """The photos endpoint queries the database for fotos in a specific radious of a location.""" - return Elastic().search_documents(latitude=latitude, longitude=longitude, radius=f"{radius}m") + return Elastic().search_documents(longitude=longitude, latitude=latitude, radius=f"{radius}m") diff --git a/api/tests/test_elastic.py b/api/tests/test_elastic.py index 1ea57cf..e881eb2 100644 --- a/api/tests/test_elastic.py +++ b/api/tests/test_elastic.py @@ -9,7 +9,7 @@ def test_index_exists(self): self.assertTrue(self.elastic.connection.indices.exists(index=settings.elastic_index)) def test_index_and_query_document(self): - self.assertEqual([], self.elastic.search_documents(48.1285358227, 11.5751872644, "1km")) + self.assertEqual([], self.elastic.search_documents(11.5751872644, 48.1285358227, "1km")) self.elastic.index( { "title": "Fraunhofer Apotheke", @@ -22,5 +22,5 @@ def test_index_and_query_document(self): ) self.assertEqual( ["Fraunhofer Apotheke"], - list(map(itemgetter("title"), self.elastic.search_documents(48.1285358227, 11.5751872644, "1km"))), + list(map(itemgetter("title"), self.elastic.search_documents(11.5751872644, 48.1285358227, "1km"))), ) diff --git a/api/tests/test_http.py b/api/tests/test_http.py index b9d2c12..729def5 100644 --- a/api/tests/test_http.py +++ b/api/tests/test_http.py @@ -35,8 +35,8 @@ def test_photos_querying(self): response = self.client.get( "/api/photos", params={ - "latitude": 47.16136672113505, "longitude": 8.513045174201151, + "latitude": 47.16136672113505, "radius": 1000000, }, ) @@ -46,8 +46,8 @@ def test_photos_querying(self): response = self.client.get( "/api/photos", params={ - "latitude": 47.16136672113505, "longitude": 8.513045174201151, + "latitude": 47.16136672113505, "radius": 10, }, )