Skip to content

Commit

Permalink
api: make coordinates ordering consistent.
Browse files Browse the repository at this point in the history
  • Loading branch information
jone committed Sep 6, 2024
1 parent 77dc9fa commit 20f9914
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions api/app/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}}},
}
}
)
Expand Down
4 changes: 2 additions & 2 deletions api/app/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
4 changes: 2 additions & 2 deletions api/tests/test_elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"))),
)
4 changes: 2 additions & 2 deletions api/tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
)
Expand All @@ -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,
},
)
Expand Down

0 comments on commit 20f9914

Please sign in to comment.