Skip to content

Commit 6e74b21

Browse files
Update collection update endpoint. (#631)
* Update collection update endpoint. * Fixing line length. * Updating registration and tests. * Adding tests to make file. * Registry and async update_collection fix. * Fixing pre-commit error. --------- Co-authored-by: Vincent Sarago <[email protected]>
1 parent d18f2d6 commit 6e74b21

File tree

5 files changed

+21
-13
lines changed

5 files changed

+21
-13
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
### Changed
1010

11+
* Updated the collection update endpoint to match with the collection-transaction extension. ([#630](https://github.com/stac-utils/stac-fastapi/issues/630))
1112
* Improve bbox and datetime typing ([#490](https://github.com/stac-utils/stac-fastapi/pull/490)
1213
* Add `items` link to inferred link relations ([#634](https://github.com/stac-utils/stac-fastapi/issues/634))
1314
* Make sure FastAPI uses Pydantic validation and serialization by not wrapping endpoint output with a Response object ([#650](https://github.com/stac-utils/stac-fastapi/pull/650))

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ docs-image:
1818
docs: docs-image
1919
docker-compose -f docker-compose.docs.yml \
2020
run docs
21+
22+
.PHONY: test
23+
test: image
24+
pytest .

stac_fastapi/api/tests/test_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def test_openapi_content_type(self):
6161
def test_build_api_with_route_dependencies(self):
6262
routes = [
6363
{"path": "/collections", "method": "POST"},
64-
{"path": "/collections", "method": "PUT"},
64+
{"path": "/collections/{collectionId}", "method": "PUT"},
6565
{"path": "/collections/{collectionId}", "method": "DELETE"},
6666
{"path": "/collections/{collectionId}/items", "method": "POST"},
6767
{"path": "/collections/{collectionId}/items/{itemId}", "method": "PUT"},
@@ -74,7 +74,7 @@ def test_build_api_with_route_dependencies(self):
7474
def test_add_route_dependencies_after_building_api(self):
7575
routes = [
7676
{"path": "/collections", "method": "POST"},
77-
{"path": "/collections", "method": "PUT"},
77+
{"path": "/collections/{collectionId}", "method": "PUT"},
7878
{"path": "/collections/{collectionId}", "method": "DELETE"},
7979
{"path": "/collections/{collectionId}/items", "method": "POST"},
8080
{"path": "/collections/{collectionId}/items/{itemId}", "method": "PUT"},

stac_fastapi/extensions/stac_fastapi/extensions/core/transaction.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Transaction extension."""
2+
23
from typing import List, Optional, Type, Union
34

45
import attr
@@ -117,10 +118,10 @@ def register_create_collection(self):
117118
)
118119

119120
def register_update_collection(self):
120-
"""Register update collection endpoint (PUT /collections)."""
121+
"""Register update collection endpoint (PUT /collections/{collection_id})."""
121122
self.router.add_api_route(
122123
name="Update Collection",
123-
path="/collections",
124+
path="/collections/{collection_id}",
124125
response_model=Collection if self.settings.enable_response_models else None,
125126
response_class=self.response_class,
126127
response_model_exclude_unset=True,

stac_fastapi/types/stac_fastapi/types/core.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Base clients."""
2+
23
import abc
34
from typing import Any, Dict, List, Optional, Union
45
from urllib.parse import urljoin
@@ -101,18 +102,18 @@ def create_collection(
101102

102103
@abc.abstractmethod
103104
def update_collection(
104-
self, collection: stac_types.Collection, **kwargs
105+
self, collection_id: str, collection: stac_types.Collection, **kwargs
105106
) -> Optional[Union[stac_types.Collection, Response]]:
106107
"""Perform a complete update on an existing collection.
107108
108-
Called with `PUT /collections`. It is expected that this item already
109-
exists. The update should do a diff against the saved collection and
109+
Called with `PUT /collections/{collection_id}`. It is expected that this item
110+
already exists. The update should do a diff against the saved collection and
110111
perform any necessary updates. Partial updates are not supported by the
111112
transactions extension.
112113
113114
Args:
114-
collection: the collection (must be complete)
115-
collection_id: the id of the collection from the resource path
115+
collection_id: id of the existing collection to be updated
116+
collection: the updated collection (must be complete)
116117
117118
Returns:
118119
The updated collection.
@@ -214,17 +215,18 @@ async def create_collection(
214215

215216
@abc.abstractmethod
216217
async def update_collection(
217-
self, collection: stac_types.Collection, **kwargs
218+
self, collection_id: str, collection: stac_types.Collection, **kwargs
218219
) -> Optional[Union[stac_types.Collection, Response]]:
219220
"""Perform a complete update on an existing collection.
220221
221-
Called with `PUT /collections`. It is expected that this item already
222-
exists. The update should do a diff against the saved collection and
222+
Called with `PUT /collections/{collection_id}`. It is expected that this item
223+
already exists. The update should do a diff against the saved collection and
223224
perform any necessary updates. Partial updates are not supported by the
224225
transactions extension.
225226
226227
Args:
227-
collection: the collection (must be complete)
228+
collection_id: id of the existing collection to be updated
229+
collection: the updated collection (must be complete)
228230
229231
Returns:
230232
The updated collection.

0 commit comments

Comments
 (0)