Skip to content

Commit

Permalink
update collections endpoit in raster API
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago committed Oct 6, 2023
1 parent 9383516 commit b90932d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/tests/test_raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,16 @@ def test_item():
in resp.json()["tiles"][0]
)
assert resp.json()["bounds"] == [-85.5501, 36.1749, -85.5249, 36.2001]


def test_collections():
"""test collection endpoints."""
resp = httpx.get(
f"{raster_endpoint}/collections",
)
assert resp.status_code == 200
assert resp.headers["content-type"] == "application/json"

collections = resp.json()
assert len(collections) == 1
assert collections[0]["id"] == "noaa-emergency-response"
8 changes: 5 additions & 3 deletions runtime/eoapi/raster/eoapi/raster/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from eoapi.raster.config import ApiSettings
from fastapi import Depends, FastAPI, Query
from psycopg import OperationalError
from psycopg.rows import dict_row
from psycopg_pool import PoolTimeout
from starlette.middleware.cors import CORSMiddleware
from starlette.requests import Request
Expand Down Expand Up @@ -118,9 +119,10 @@ async def mosaic_builder(request: Request):
async def list_collection(request: Request):
"""list collections."""
with request.app.state.dbpool.connection() as conn:
with conn.cursor() as cursor:
cursor.execute("SELECT * FROM collections;")
return [t[2] for t in cursor.fetchall() if t]
with conn.cursor(row_factory=dict_row) as cursor:
cursor.execute("SELECT * FROM pgstac.all_collections();")
r = cursor.fetchone()
return r.get("all_collections", [])


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

0 comments on commit b90932d

Please sign in to comment.