Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## [Unreleased]

## [4.0.1] - 2025-02-06

### Added

- add `numberReturned` and `numberMatched` in `/collections` response

## [4.0.0] - 2025-02-03

### Changed
Expand Down Expand Up @@ -366,7 +372,8 @@ As a part of this release, this repository was extracted from the main

- First PyPi release!

[Unreleased]: <https://github.com/stac-utils/stac-fastapi-pgstac/compare/4.0.0..main>
[Unreleased]: <https://github.com/stac-utils/stac-fastapi-pgstac/compare/4.0.1..main>
[4.0.1]: <https://github.com/stac-utils/stac-fastapi-pgstac/compare/4.0.0..4.0.1>
[4.0.0]: <https://github.com/stac-utils/stac-fastapi-pgstac/compare/3.0.1..4.0.0>
[3.0.1]: <https://github.com/stac-utils/stac-fastapi-pgstac/compare/3.0.0..3.0.1>
[3.0.0]: <https://github.com/stac-utils/stac-fastapi-pgstac/compare/2.5.0..3.0.0>
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.nginx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ services:
command: [ "nginx-debug", "-g", "daemon off;" ]
app:
environment:
- UVICORN_ROOT_PATH=/api/v1/pgstac
- ROOT_PATH=/api/v1/pgstac
6 changes: 6 additions & 0 deletions stac_fastapi/pgstac/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ async def all_collections( # noqa: C901
return Collections(
collections=linked_collections or [],
links=links,
numberMatched=collections_result.get(
"numberMatched", len(linked_collections)
),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

numberMatched will not be set in collections_result when we're not using pgstac's collection-search so we set numberMatched to the len of returned collections

numberReturned=collections_result.get(
"numberReturned", len(linked_collections)
),
)

async def get_collection(
Expand Down
14 changes: 14 additions & 0 deletions tests/resources/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ async def test_nocollections(
):
resp = await app_client.get("/collections")
assert resp.status_code == 200
assert resp.json()["numberReturned"] == 0


async def test_returns_valid_collection(app_client, load_test_data):
Expand Down Expand Up @@ -168,6 +169,9 @@ async def test_returns_valid_links_in_collections(app_client, load_test_data):
resp = await app_client.get("/collections")
assert resp.status_code == 200
resp_json = resp.json()
assert resp.json()["numberReturned"]
assert resp.json()["numberMatched"]

collections = resp_json["collections"]
# Find collection in list by ID
single_coll = next(coll for coll in collections if coll["id"] == in_json["id"])
Expand Down Expand Up @@ -317,6 +321,8 @@ async def test_collection_search_freetext(
"/collections",
params={"q": "temperature"},
)
assert resp.json()["numberReturned"] == 1
assert resp.json()["numberMatched"] == 1
assert len(resp.json()["collections"]) == 1
assert resp.json()["collections"][0]["id"] == load_test2_collection.id

Expand All @@ -341,13 +347,17 @@ async def test_all_collections_with_pagination(app_client, load_test_data):
assert resp.status_code == 201

resp = await app_client.get("/collections")
assert resp.json()["numberReturned"] == 10
assert resp.json()["numberMatched"] == 12
cols = resp.json()["collections"]
assert len(cols) == 10
links = resp.json()["links"]
assert len(links) == 3
assert {"root", "self", "next"} == {link["rel"] for link in links}

resp = await app_client.get("/collections", params={"limit": 12})
assert resp.json()["numberReturned"] == 12
assert resp.json()["numberMatched"] == 12
cols = resp.json()["collections"]
assert len(cols) == 12
links = resp.json()["links"]
Expand All @@ -369,6 +379,8 @@ async def test_all_collections_without_pagination(app_client_no_ext, load_test_d
assert resp.status_code == 201

resp = await app_client_no_ext.get("/collections")
assert resp.json()["numberReturned"] == 12
assert resp.json()["numberMatched"] == 12
cols = resp.json()["collections"]
assert len(cols) == 12
links = resp.json()["links"]
Expand All @@ -382,6 +394,8 @@ async def test_get_collections_search_pagination(
app_client, load_test_collection, load_test2_collection
):
resp = await app_client.get("/collections")
assert resp.json()["numberReturned"] == 2
assert resp.json()["numberMatched"] == 2
cols = resp.json()["collections"]
assert len(cols) == 2
links = resp.json()["links"]
Expand Down
Loading