16
16
from stac_fastapi .types .core import AsyncBaseCoreClient
17
17
from stac_fastapi .types .errors import InvalidQueryParameter , NotFoundError
18
18
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
20
20
from stac_pydantic .links import Relations
21
21
from stac_pydantic .shared import MimeTypes
22
22
36
36
@attr .s
37
37
class CoreCrudClient (AsyncBaseCoreClient ):
38
38
"""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
39
63
40
64
async def all_collections (self , request : Request , ** kwargs ) -> Collections :
41
65
"""Read all collections from the database."""
@@ -55,6 +79,16 @@ async def all_collections(self, request: Request, **kwargs) -> Collections:
55
79
collection_id = coll ["id" ], request = request
56
80
).get_links (extra_links = coll .get ("links" ))
57
81
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
+
58
92
linked_collections .append (coll )
59
93
60
94
links = [
@@ -107,6 +141,17 @@ async def get_collection(
107
141
collection_id = collection_id , request = request
108
142
).get_links (extra_links = collection .get ("links" ))
109
143
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
+
110
155
return Collection (** collection )
111
156
112
157
async def _get_base_item (
@@ -277,6 +322,15 @@ async def item_collection(
277
322
"token" : token ,
278
323
}
279
324
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
+
280
334
clean = {}
281
335
for k , v in base_args .items ():
282
336
if v is not None and v != []:
0 commit comments