|
8 | 8 | from fastapi import HTTPException, Request |
9 | 9 | from stac_fastapi.pgstac.core import CoreCrudClient |
10 | 10 | from stac_fastapi.types.errors import NotFoundError |
| 11 | +from stac_fastapi.types.requests import get_base_url |
11 | 12 | from stac_fastapi.types.stac import ( |
12 | 13 | Collection, |
13 | 14 | Collections, |
14 | 15 | Item, |
15 | 16 | ItemCollection, |
16 | 17 | LandingPage, |
17 | 18 | ) |
| 19 | +from stac_pydantic.links import Relations |
| 20 | +from stac_pydantic.shared import MimeTypes |
18 | 21 |
|
19 | 22 | from pccommon.config import get_all_render_configs, get_render_config |
20 | 23 | from pccommon.config.collections import DefaultRenderConfig |
@@ -238,11 +241,87 @@ async def _fetch() -> ItemCollection: |
238 | 241 | return await cached_result(_fetch, cache_key, request) |
239 | 242 |
|
240 | 243 | async def landing_page(self, request: Request, **kwargs: Any) -> LandingPage: |
241 | | - _super: CoreCrudClient = super() |
| 244 | + """Landing page.""" |
242 | 245 |
|
243 | 246 | 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) |
246 | 325 |
|
247 | 326 | return await cached_result(_fetch, CACHE_KEY_LANDING_PAGE, request) |
248 | 327 |
|
|
0 commit comments