From 352062a5f8f8822ac1c1806ac24067d545fb8b0b Mon Sep 17 00:00:00 2001 From: jakeross Date: Wed, 23 Jul 2025 13:18:36 -0600 Subject: [PATCH 1/2] fixed thing api, tests. standardized to /thing//. e.g /thing/well/1 and /thing/base/1 --- api/thing.py | 46 ++------------------------------------------- tests/test_thing.py | 13 +++++++------ 2 files changed, 9 insertions(+), 50 deletions(-) diff --git a/api/thing.py b/api/thing.py index 0494aaee8..9b2df50a5 100644 --- a/api/thing.py +++ b/api/thing.py @@ -78,53 +78,11 @@ def wkb_to_geojson(wkb_element): @router.get("") def get_things( session: session_dependency, - thing_id: int = None, ) -> CustomPage[ThingResponse]: - """ - Retrieve all things or filter by type. - """ - # if thing_type == "well": - # sql = select(Thing).join(WellThing) - # elif thing_type == "spring": - # sql = select(Thing).join(SpringThing) - # else: - # sql = select(Thing) - # - # if group: - # sql = sql.join(GroupThingAssociation).join(Group).where(Group.name == group) - # - # if response_format == "geojson": - # # todo: implement geojson response - # def make_feature(thing: Thing) -> Feature: - # - # # todo: get latest location - # geometry = thing.locations[0].point - # # Convert geometry to GeoJSON format - # - # geojson_geometry = wkb_to_geojson(geometry) - # properties = { - # "id": thing.id, - # "name": thing.name, - # "type": thing_type, - # "group": group, - # } - # return Feature(geometry=geojson_geometry, properties=properties) - # - # things = session.scalars(sql).all() - # features = [make_feature(thing) for thing in things] - # return FeatureCollectionResponse(features=features) - # else: - # # return paginate(query=sql, conn=session) - # return session.scalars(sql).all() - if thing_id: - sql = select(Thing).where(Thing.id == thing_id) - return paginate(query=sql, conn=session) - else: - - return paginated_all_getter(session, Thing) + return paginated_all_getter(session, Thing) -@router.get("", summary="Get thing by ID") +@router.get("/base/{thing_id}", summary="Get thing by ID") async def get_thing_by_id(thing_id: int, session: session_dependency) -> ThingResponse: """ Retrieve a thing by ID from the database. diff --git a/tests/test_thing.py b/tests/test_thing.py index 92c555c4b..bfb68db10 100644 --- a/tests/test_thing.py +++ b/tests/test_thing.py @@ -143,14 +143,15 @@ def test_add_thing_link(): # ===================== get ========================== def test_get_thing_by_id(): - response = client.get("/thing?thing_id=1") + # response = client.get("/thing?thing_id=1") + response = client.get("/thing/base/1") assert response.status_code == 200 data = response.json() - assert "items" in data - items = data["items"] - assert len(items) == 1 - assert items[0]["id"] == 1 - assert items[0]["name"] == "Test Thing" + # assert "items" in data + # items = data["items"] + # assert len(items) == 1 + assert data["id"] == 1 + assert data["name"] == "Test Thing" def test_get_wells(): From 2a64d2053c1368a25fdde50fa0a6d213cac4238d Mon Sep 17 00:00:00 2001 From: jakeross Date: Thu, 24 Jul 2025 22:18:29 -0600 Subject: [PATCH 2/2] fix: deprecated get thing by id --- tests/test_thing.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/test_thing.py b/tests/test_thing.py index 2b4b438d4..fdca250b9 100644 --- a/tests/test_thing.py +++ b/tests/test_thing.py @@ -147,16 +147,16 @@ def test_add_thing_link(): # ===================== get ========================== -def test_get_thing_by_id(): - # response = client.get("/thing?thing_id=1") - response = client.get("/thing/base/1") - assert response.status_code == 200 - data = response.json() - # assert "items" in data - # items = data["items"] - # assert len(items) == 1 - assert data["id"] == 1 - assert data["name"] == "Test Thing" +# def test_get_thing_by_id(): +# # response = client.get("/thing?thing_id=1") +# response = client.get("/thing/base/1") +# assert response.status_code == 200 +# data = response.json() +# # assert "items" in data +# # items = data["items"] +# # assert len(items) == 1 +# assert data["id"] == 1 +# assert data["name"] == "Test Thing" def test_get_wells():