Skip to content

Commit 7392a67

Browse files
add numberMatched and numberReturned for /collections (#197)
1 parent d42025a commit 7392a67

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

CHANGES.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## [Unreleased]
44

5+
## [4.0.1] - 2025-02-06
6+
7+
### Added
8+
9+
- add `numberReturned` and `numberMatched` in `/collections` response
10+
511
## [4.0.0] - 2025-02-03
612

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

367373
- First PyPi release!
368374

369-
[Unreleased]: <https://github.com/stac-utils/stac-fastapi-pgstac/compare/4.0.0..main>
375+
[Unreleased]: <https://github.com/stac-utils/stac-fastapi-pgstac/compare/4.0.1..main>
376+
[4.0.1]: <https://github.com/stac-utils/stac-fastapi-pgstac/compare/4.0.0..4.0.1>
370377
[4.0.0]: <https://github.com/stac-utils/stac-fastapi-pgstac/compare/3.0.1..4.0.0>
371378
[3.0.1]: <https://github.com/stac-utils/stac-fastapi-pgstac/compare/3.0.0..3.0.1>
372379
[3.0.0]: <https://github.com/stac-utils/stac-fastapi-pgstac/compare/2.5.0..3.0.0>

docker-compose.nginx.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ services:
1010
command: [ "nginx-debug", "-g", "daemon off;" ]
1111
app:
1212
environment:
13-
- UVICORN_ROOT_PATH=/api/v1/pgstac
13+
- ROOT_PATH=/api/v1/pgstac

stac_fastapi/pgstac/core.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ async def all_collections( # noqa: C901
148148
return Collections(
149149
collections=linked_collections or [],
150150
links=links,
151+
numberMatched=collections_result.get(
152+
"numberMatched", len(linked_collections)
153+
),
154+
numberReturned=collections_result.get(
155+
"numberReturned", len(linked_collections)
156+
),
151157
)
152158

153159
async def get_collection(

tests/resources/test_collection.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ async def test_nocollections(
116116
):
117117
resp = await app_client.get("/collections")
118118
assert resp.status_code == 200
119+
assert resp.json()["numberReturned"] == 0
119120

120121

121122
async def test_returns_valid_collection(app_client, load_test_data):
@@ -168,6 +169,9 @@ async def test_returns_valid_links_in_collections(app_client, load_test_data):
168169
resp = await app_client.get("/collections")
169170
assert resp.status_code == 200
170171
resp_json = resp.json()
172+
assert resp.json()["numberReturned"]
173+
assert resp.json()["numberMatched"]
174+
171175
collections = resp_json["collections"]
172176
# Find collection in list by ID
173177
single_coll = next(coll for coll in collections if coll["id"] == in_json["id"])
@@ -317,6 +321,8 @@ async def test_collection_search_freetext(
317321
"/collections",
318322
params={"q": "temperature"},
319323
)
324+
assert resp.json()["numberReturned"] == 1
325+
assert resp.json()["numberMatched"] == 1
320326
assert len(resp.json()["collections"]) == 1
321327
assert resp.json()["collections"][0]["id"] == load_test2_collection.id
322328

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

343349
resp = await app_client.get("/collections")
350+
assert resp.json()["numberReturned"] == 10
351+
assert resp.json()["numberMatched"] == 12
344352
cols = resp.json()["collections"]
345353
assert len(cols) == 10
346354
links = resp.json()["links"]
347355
assert len(links) == 3
348356
assert {"root", "self", "next"} == {link["rel"] for link in links}
349357

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

371381
resp = await app_client_no_ext.get("/collections")
382+
assert resp.json()["numberReturned"] == 12
383+
assert resp.json()["numberMatched"] == 12
372384
cols = resp.json()["collections"]
373385
assert len(cols) == 12
374386
links = resp.json()["links"]
@@ -382,6 +394,8 @@ async def test_get_collections_search_pagination(
382394
app_client, load_test_collection, load_test2_collection
383395
):
384396
resp = await app_client.get("/collections")
397+
assert resp.json()["numberReturned"] == 2
398+
assert resp.json()["numberMatched"] == 2
385399
cols = resp.json()["collections"]
386400
assert len(cols) == 2
387401
links = resp.json()["links"]

0 commit comments

Comments
 (0)