From 2d6cb4dabb5847fa22e4734187779dcbcb7b41b9 Mon Sep 17 00:00:00 2001 From: rhysrevans3 <34507919+rhysrevans3@users.noreply.github.com> Date: Tue, 17 Sep 2024 11:30:49 +0100 Subject: [PATCH] Updating collection self link for collections page. (#297) **Related Issue(s):** - #296 **Description:** Updating `CollectionLinks` to generate correct `self` link for `collections` endpoint. **PR Checklist:** - [x] Code is formatted and linted (run `pre-commit run --all-files`) - [x] Tests pass (run `make test`) - [x] Documentation has been updated to reflect changes, if applicable - [x] Changes are added to the changelog --- CHANGELOG.md | 1 + stac_fastapi/core/stac_fastapi/core/models/links.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75d12221..e6fd124f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed +- Updated CollectionLinks to generate correct `self` link for collections endpoint. [#297](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/297) - Refactored aggregation in database logic. [#294](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/294) - Fixed the `self` link for the `/collections/{collection_id}/aggregations` endpoint. [#295](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/295) diff --git a/stac_fastapi/core/stac_fastapi/core/models/links.py b/stac_fastapi/core/stac_fastapi/core/models/links.py index f12ad98f..76f0ce5b 100644 --- a/stac_fastapi/core/stac_fastapi/core/models/links.py +++ b/stac_fastapi/core/stac_fastapi/core/models/links.py @@ -114,6 +114,14 @@ class CollectionLinks(BaseLinks): collection_id: str = attr.ib() extensions: List[str] = attr.ib(default=attr.Factory(list)) + def link_self(self) -> Dict: + """Return the self link.""" + return dict( + rel=Relations.self.value, + type=MimeTypes.json.value, + href=urljoin(self.base_url, f"collections/{self.collection_id}"), + ) + def link_parent(self) -> Dict[str, Any]: """Create the `parent` link.""" return dict(rel=Relations.parent, type=MimeTypes.json.value, href=self.base_url)