Skip to content

Commit

Permalink
Updating collection self link for collections page. (#297)
Browse files Browse the repository at this point in the history
**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
  • Loading branch information
rhysrevans3 committed Sep 17, 2024
1 parent c25229e commit 2d6cb4d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 8 additions & 0 deletions stac_fastapi/core/stac_fastapi/core/models/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2d6cb4d

Please sign in to comment.