Skip to content

Commit b234f1c

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

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

stac_fastapi/pgstac/core.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
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 Collection, Collections, Item, ItemCollection, LandingPage
2020
from stac_pydantic.links import Relations
2121
from stac_pydantic.shared import MimeTypes
2222

@@ -36,6 +36,30 @@
3636
@attr.s
3737
class CoreCrudClient(AsyncBaseCoreClient):
3838
"""Client for core endpoints defined by stac."""
39+
40+
async def landing_page(self, **kwargs) -> LandingPage:
41+
"""Landing page.
42+
43+
Called with `GET /`.
44+
45+
Returns:
46+
API landing page, serving as an entry point to the API.
47+
"""
48+
request: Request = kwargs["request"]
49+
base_url = get_base_url(request)
50+
landing_page = await super().landing_page(**kwargs)
51+
52+
if self.extension_is_enabled("FilterExtension"):
53+
landing_page["links"].append(
54+
{
55+
"rel": "http://www.opengis.net/def/rel/ogc/1.0/queryables",
56+
"type": "application/schema+json",
57+
"title": "Queryables",
58+
"href": urljoin(base_url, "queryables"),
59+
}
60+
)
61+
62+
return landing_page
3963

4064
async def all_collections(self, request: Request, **kwargs) -> Collections:
4165
"""Read all collections from the database."""
@@ -55,6 +79,16 @@ async def all_collections(self, request: Request, **kwargs) -> Collections:
5579
collection_id=coll["id"], request=request
5680
).get_links(extra_links=coll.get("links"))
5781

82+
if self.extension_is_enabled("FilterExtension"):
83+
coll["links"].append(
84+
{
85+
"rel": "http://www.opengis.net/def/rel/ogc/1.0/queryables",
86+
"type": "application/schema+json",
87+
"title": "Queryables",
88+
"href": urljoin(base_url, f"collections/{coll['id']}/queryables"),
89+
}
90+
)
91+
5892
linked_collections.append(coll)
5993

6094
links = [
@@ -107,6 +141,17 @@ async def get_collection(
107141
collection_id=collection_id, request=request
108142
).get_links(extra_links=collection.get("links"))
109143

144+
if self.extension_is_enabled("FilterExtension"):
145+
base_url = get_base_url(request)
146+
collection["links"].append(
147+
{
148+
"rel": "http://www.opengis.net/def/rel/ogc/1.0/queryables",
149+
"type": "application/schema+json",
150+
"title": "Queryables",
151+
"href": urljoin(base_url, f"collections/{collection_id}/queryables"),
152+
}
153+
)
154+
110155
return Collection(**collection)
111156

112157
async def _get_base_item(
@@ -277,6 +322,15 @@ async def item_collection(
277322
"token": token,
278323
}
279324

325+
if self.extension_is_enabled("FilterExtension"):
326+
filter_lang = request.query_params.get("filter-lang", None)
327+
filter = request.query_params.get("filter", "").strip()
328+
329+
if len(filter) > 0 and filter_lang == "cql2-text":
330+
ast = parse_cql2_text(filter)
331+
base_args["filter"] = orjson.loads(to_cql2(ast))
332+
base_args["filter-lang"] = "cql2-json"
333+
280334
clean = {}
281335
for k, v in base_args.items():
282336
if v is not None and v != []:

0 commit comments

Comments
 (0)