|
| 1 | +"""Get Queryables.""" |
| 2 | +from typing import Any, Optional |
| 3 | + |
| 4 | +from buildpg import render |
| 5 | +from fastapi import Request |
| 6 | +from fastapi.responses import JSONResponse |
| 7 | + |
| 8 | +from stac_fastapi.types.core import AsyncBaseFiltersClient |
| 9 | + |
| 10 | + |
| 11 | +class FiltersClient(AsyncBaseFiltersClient): |
| 12 | + """Defines a pattern for implementing the STAC filter extension.""" |
| 13 | + |
| 14 | + async def get_queryables( |
| 15 | + self, request: Request, collection_id: Optional[str] = None, **kwargs: Any |
| 16 | + ) -> JSONResponse: |
| 17 | + """Get the queryables available for the given collection_id. |
| 18 | +
|
| 19 | + If collection_id is None, returns the intersection of all |
| 20 | + queryables over all collections. |
| 21 | + This base implementation returns a blank queryable schema. This is not allowed |
| 22 | + under OGC CQL but it is allowed by the STAC API Filter Extension |
| 23 | + https://github.com/radiantearth/stac-api-spec/tree/master/fragments/filter#queryables |
| 24 | + """ |
| 25 | + pool = request.app.state.readpool |
| 26 | + |
| 27 | + async with pool.acquire() as conn: |
| 28 | + q, p = render( |
| 29 | + """ |
| 30 | + SELECT * FROM get_queryables(:collection::text); |
| 31 | + """, |
| 32 | + collection=collection_id, |
| 33 | + ) |
| 34 | + queryables = await conn.fetchval(q, *p) |
| 35 | + queryables["$id"] = str(request.url) |
| 36 | + headers = {"Content-Type": "application/schema+json"} |
| 37 | + return JSONResponse(queryables, headers=headers) |
0 commit comments