Skip to content

Commit 704478e

Browse files
committed
fix, pgstac: self link, item collection endpoint
1 parent 61d9119 commit 704478e

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

stac_fastapi/pgstac/stac_fastapi/pgstac/core.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
from starlette.requests import Request
1919

2020
from stac_fastapi.pgstac.config import Settings
21-
from stac_fastapi.pgstac.models.links import CollectionLinks, ItemLinks, PagingLinks
21+
from stac_fastapi.pgstac.models.links import (
22+
CollectionLinks,
23+
ItemCollectionLinks,
24+
ItemLinks,
25+
PagingLinks,
26+
)
2227
from stac_fastapi.pgstac.types.search import PgstacSearch
2328
from stac_fastapi.pgstac.utils import filter_fields
2429
from stac_fastapi.types.core import AsyncBaseCoreClient
@@ -286,7 +291,7 @@ async def item_collection(
286291
**clean,
287292
)
288293
item_collection = await self._search_base(req, **kwargs)
289-
links = await CollectionLinks(
294+
links = await ItemCollectionLinks(
290295
collection_id=collection_id, request=kwargs["request"]
291296
).get_links(extra_links=item_collection["links"])
292297
item_collection["links"] = links

stac_fastapi/pgstac/stac_fastapi/pgstac/models/links.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,27 @@ def link_items(self) -> Dict:
206206
)
207207

208208

209+
@attr.s
210+
class ItemCollectionLinks(CollectionLinksBase):
211+
"""Create inferred links specific to collections."""
212+
213+
def link_self(self) -> Dict:
214+
"""Return the self link."""
215+
return dict(
216+
rel=Relations.self.value,
217+
type=MimeTypes.geojson.value,
218+
href=self.resolve(f"collections/{self.collection_id}/items"),
219+
)
220+
221+
def link_parent(self) -> Dict:
222+
"""Create the `parent` link."""
223+
return self.collection_link(rel=Relations.parent.value)
224+
225+
def link_collection(self) -> Dict:
226+
"""Create the `collection` link."""
227+
return self.collection_link()
228+
229+
209230
@attr.s
210231
class ItemLinks(CollectionLinksBase):
211232
"""Create inferred links specific to items."""

stac_fastapi/pgstac/tests/api/test_api.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ async def test_get_features_content_type(app_client, load_test_collection):
5151
assert resp.headers["content-type"] == "application/geo+json"
5252

5353

54+
async def test_get_features_self_link(app_client, load_test_collection):
55+
# https://github.com/stac-utils/stac-fastapi/issues/483
56+
resp = await app_client.get(f"collections/{load_test_collection.id}/items")
57+
assert resp.status_code == 200
58+
resp_json = resp.json()
59+
self_link = next(
60+
(link for link in resp_json["links"] if link["rel"] == "self"), None
61+
)
62+
assert self_link is not None
63+
assert self_link["href"].endswith("/items")
64+
65+
5466
async def test_get_feature_content_type(
5567
app_client, load_test_collection, load_test_item
5668
):

0 commit comments

Comments
 (0)