88from fastapi import HTTPException , Request
99from stac_fastapi .pgstac .core import CoreCrudClient
1010from stac_fastapi .types .errors import NotFoundError
11+ from stac_fastapi .types .requests import get_base_url
1112from stac_fastapi .types .stac import (
1213 Collection ,
1314 Collections ,
1415 Item ,
1516 ItemCollection ,
1617 LandingPage ,
1718)
19+ from stac_pydantic .links import Relations
20+ from stac_pydantic .shared import MimeTypes
1821
1922from pccommon .config import get_all_render_configs , get_render_config
2023from pccommon .config .collections import DefaultRenderConfig
@@ -220,7 +223,7 @@ async def _fetch() -> ItemCollection:
220223 search_request .collections is None
221224 and "collection=" not in str (request .url )
222225 and '{"property":"collection"}'
223- not in orjson .dumps (search_request .filter ).decode ("utf-8" )
226+ not in orjson .dumps (search_request .filter_expr ).decode ("utf-8" )
224227 ):
225228 raise HTTPException (status_code = 422 , detail = "collection is required" )
226229
@@ -238,11 +241,87 @@ async def _fetch() -> ItemCollection:
238241 return await cached_result (_fetch , cache_key , request )
239242
240243 async def landing_page (self , request : Request , ** kwargs : Any ) -> LandingPage :
241- _super : CoreCrudClient = super ()
244+ """Landing page."""
242245
243246 async def _fetch () -> LandingPage :
244- landing = await _super .landing_page (request = request , ** kwargs )
245- return landing
247+ """Landing page.
248+
249+ NOTE: we need a custom landing page implementation
250+ to avoid the call to `all_collections` method.
251+
252+ TODO: replace this with:
253+ ```
254+ _super: CoreCrudClient = super()
255+
256+ async def _fetch() -> LandingPage:
257+ landing = await _super.landing_page(request=request, **kwargs)
258+ return landing
259+ ```
260+ when switching to stac-fastapi >=v5.1.
261+
262+ """
263+ base_url = get_base_url (request )
264+
265+ landing_page = self ._landing_page (
266+ base_url = base_url ,
267+ conformance_classes = self .conformance_classes (),
268+ extension_schemas = [],
269+ )
270+
271+ # Add Queryables link
272+ if self .extension_is_enabled (
273+ "FilterExtension"
274+ ) or self .extension_is_enabled ("SearchFilterExtension" ):
275+ landing_page ["links" ].append (
276+ {
277+ "rel" : Relations .queryables .value ,
278+ "type" : MimeTypes .jsonschema .value ,
279+ "title" : "Queryables available for this Catalog" ,
280+ "href" : urljoin (base_url , "queryables" ),
281+ "method" : "GET" ,
282+ }
283+ )
284+
285+ # Add Aggregation links
286+ if self .extension_is_enabled ("AggregationExtension" ):
287+ landing_page ["links" ].extend (
288+ [
289+ {
290+ "rel" : "aggregate" ,
291+ "type" : "application/json" ,
292+ "title" : "Aggregate" ,
293+ "href" : urljoin (base_url , "aggregate" ),
294+ },
295+ {
296+ "rel" : "aggregations" ,
297+ "type" : "application/json" ,
298+ "title" : "Aggregations" ,
299+ "href" : urljoin (base_url , "aggregations" ),
300+ },
301+ ]
302+ )
303+
304+ # Add OpenAPI URL
305+ landing_page ["links" ].append (
306+ {
307+ "rel" : Relations .service_desc .value ,
308+ "type" : MimeTypes .openapi .value ,
309+ "title" : "OpenAPI service description" ,
310+ "href" : str (request .url_for ("openapi" )),
311+ }
312+ )
313+
314+ # Add human readable service-doc
315+ landing_page ["links" ].append (
316+ {
317+ "rel" : Relations .service_doc .value ,
318+ "type" : MimeTypes .html .value ,
319+ "title" : "OpenAPI service documentation" ,
320+ "href" : str (request .url_for ("swagger_ui_html" )),
321+ }
322+ )
323+
324+ return LandingPage (** landing_page )
246325
247326 return await cached_result (_fetch , CACHE_KEY_LANDING_PAGE , request )
248327
@@ -303,6 +382,6 @@ def create(
303382 title = API_TITLE ,
304383 description = API_DESCRIPTION ,
305384 extra_conformance_classes = extra_conformance_classes ,
306- post_request_model = post_request_model ,
385+ pgstac_search_model = post_request_model ,
307386 )
308387 return it
0 commit comments