Skip to content

Commit b9c0999

Browse files
committed
Enable search on /items and add queryables links
1 parent a1b0633 commit b9c0999

File tree

1 file changed

+65
-1
lines changed

1 file changed

+65
-1
lines changed

stac_fastapi/pgstac/core.py

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@
1616
from stac_fastapi.types.core import AsyncBaseCoreClient
1717
from stac_fastapi.types.errors import InvalidQueryParameter, NotFoundError
1818
from stac_fastapi.types.requests import get_base_url
19-
from stac_fastapi.types.stac import Collection, Collections, Item, ItemCollection
19+
from stac_fastapi.types.stac import (
20+
Collection,
21+
Collections,
22+
Item,
23+
ItemCollection,
24+
LandingPage,
25+
)
2026
from stac_pydantic.links import Relations
2127
from stac_pydantic.shared import MimeTypes
2228

@@ -37,6 +43,30 @@
3743
class CoreCrudClient(AsyncBaseCoreClient):
3844
"""Client for core endpoints defined by stac."""
3945

46+
async def landing_page(self, **kwargs) -> LandingPage:
47+
"""Landing page.
48+
49+
Called with `GET /`.
50+
51+
Returns:
52+
API landing page, serving as an entry point to the API.
53+
"""
54+
request: Request = kwargs["request"]
55+
base_url = get_base_url(request)
56+
landing_page = await super().landing_page(**kwargs)
57+
58+
if self.extension_is_enabled("FilterExtension"):
59+
landing_page["links"].append(
60+
{
61+
"rel": "http://www.opengis.net/def/rel/ogc/1.0/queryables",
62+
"type": "application/schema+json",
63+
"title": "Queryables",
64+
"href": urljoin(base_url, "queryables"),
65+
}
66+
)
67+
68+
return landing_page
69+
4070
async def all_collections(self, request: Request, **kwargs) -> Collections:
4171
"""Read all collections from the database."""
4272
base_url = get_base_url(request)
@@ -55,6 +85,18 @@ async def all_collections(self, request: Request, **kwargs) -> Collections:
5585
collection_id=coll["id"], request=request
5686
).get_links(extra_links=coll.get("links"))
5787

88+
if self.extension_is_enabled("FilterExtension"):
89+
coll["links"].append(
90+
{
91+
"rel": "http://www.opengis.net/def/rel/ogc/1.0/queryables",
92+
"type": "application/schema+json",
93+
"title": "Queryables",
94+
"href": urljoin(
95+
base_url, f"collections/{coll['id']}/queryables"
96+
),
97+
}
98+
)
99+
58100
linked_collections.append(coll)
59101

60102
links = [
@@ -107,6 +149,19 @@ async def get_collection(
107149
collection_id=collection_id, request=request
108150
).get_links(extra_links=collection.get("links"))
109151

152+
if self.extension_is_enabled("FilterExtension"):
153+
base_url = get_base_url(request)
154+
collection["links"].append(
155+
{
156+
"rel": "http://www.opengis.net/def/rel/ogc/1.0/queryables",
157+
"type": "application/schema+json",
158+
"title": "Queryables",
159+
"href": urljoin(
160+
base_url, f"collections/{collection_id}/queryables"
161+
),
162+
}
163+
)
164+
110165
return Collection(**collection)
111166

112167
async def _get_base_item(
@@ -277,6 +332,15 @@ async def item_collection(
277332
"token": token,
278333
}
279334

335+
if self.extension_is_enabled("FilterExtension"):
336+
filter_lang = request.query_params.get("filter-lang", None)
337+
filter = request.query_params.get("filter", "").strip()
338+
339+
if len(filter) > 0 and filter_lang == "cql2-text":
340+
ast = parse_cql2_text(filter)
341+
base_args["filter"] = orjson.loads(to_cql2(ast))
342+
base_args["filter-lang"] = "cql2-json"
343+
280344
clean = {}
281345
for k, v in base_args.items():
282346
if v is not None and v != []:

0 commit comments

Comments
 (0)