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 (
20
+ Collection ,
21
+ Collections ,
22
+ Item ,
23
+ ItemCollection ,
24
+ LandingPage ,
25
+ )
20
26
from stac_pydantic .links import Relations
21
27
from stac_pydantic .shared import MimeTypes
22
28
37
43
class CoreCrudClient (AsyncBaseCoreClient ):
38
44
"""Client for core endpoints defined by stac."""
39
45
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
+
40
70
async def all_collections (self , request : Request , ** kwargs ) -> Collections :
41
71
"""Read all collections from the database."""
42
72
base_url = get_base_url (request )
@@ -55,6 +85,18 @@ async def all_collections(self, request: Request, **kwargs) -> Collections:
55
85
collection_id = coll ["id" ], request = request
56
86
).get_links (extra_links = coll .get ("links" ))
57
87
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
+
58
100
linked_collections .append (coll )
59
101
60
102
links = [
@@ -107,6 +149,19 @@ async def get_collection(
107
149
collection_id = collection_id , request = request
108
150
).get_links (extra_links = collection .get ("links" ))
109
151
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
+
110
165
return Collection (** collection )
111
166
112
167
async def _get_base_item (
@@ -277,6 +332,15 @@ async def item_collection(
277
332
"token" : token ,
278
333
}
279
334
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
+
280
344
clean = {}
281
345
for k , v in base_args .items ():
282
346
if v is not None and v != []:
0 commit comments