Skip to content

Commit b90932d

Browse files
committed
update collections endpoit in raster API
1 parent 9383516 commit b90932d

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

.github/workflows/tests/test_raster.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,16 @@ def test_item():
188188
in resp.json()["tiles"][0]
189189
)
190190
assert resp.json()["bounds"] == [-85.5501, 36.1749, -85.5249, 36.2001]
191+
192+
193+
def test_collections():
194+
"""test collection endpoints."""
195+
resp = httpx.get(
196+
f"{raster_endpoint}/collections",
197+
)
198+
assert resp.status_code == 200
199+
assert resp.headers["content-type"] == "application/json"
200+
201+
collections = resp.json()
202+
assert len(collections) == 1
203+
assert collections[0]["id"] == "noaa-emergency-response"

runtime/eoapi/raster/eoapi/raster/app.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from eoapi.raster.config import ApiSettings
1010
from fastapi import Depends, FastAPI, Query
1111
from psycopg import OperationalError
12+
from psycopg.rows import dict_row
1213
from psycopg_pool import PoolTimeout
1314
from starlette.middleware.cors import CORSMiddleware
1415
from starlette.requests import Request
@@ -118,9 +119,10 @@ async def mosaic_builder(request: Request):
118119
async def list_collection(request: Request):
119120
"""list collections."""
120121
with request.app.state.dbpool.connection() as conn:
121-
with conn.cursor() as cursor:
122-
cursor.execute("SELECT * FROM collections;")
123-
return [t[2] for t in cursor.fetchall() if t]
122+
with conn.cursor(row_factory=dict_row) as cursor:
123+
cursor.execute("SELECT * FROM pgstac.all_collections();")
124+
r = cursor.fetchone()
125+
return r.get("all_collections", [])
124126

125127

126128
app.include_router(mosaic.router, tags=["Mosaic"], prefix="/mosaic")

0 commit comments

Comments
 (0)