Skip to content

Commit

Permalink
Update collection update endpoint. (#631)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
rhysrevans3 and vincentsarago authored Apr 9, 2024
1 parent d18f2d6 commit 6e74b21
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Changed

* Updated the collection update endpoint to match with the collection-transaction extension. ([#630](https://github.com/stac-utils/stac-fastapi/issues/630))
* Improve bbox and datetime typing ([#490](https://github.com/stac-utils/stac-fastapi/pull/490)
* Add `items` link to inferred link relations ([#634](https://github.com/stac-utils/stac-fastapi/issues/634))
* 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))
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ docs-image:
docs: docs-image
docker-compose -f docker-compose.docs.yml \
run docs

.PHONY: test
test: image
pytest .
4 changes: 2 additions & 2 deletions stac_fastapi/api/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_openapi_content_type(self):
def test_build_api_with_route_dependencies(self):
routes = [
{"path": "/collections", "method": "POST"},
{"path": "/collections", "method": "PUT"},
{"path": "/collections/{collectionId}", "method": "PUT"},
{"path": "/collections/{collectionId}", "method": "DELETE"},
{"path": "/collections/{collectionId}/items", "method": "POST"},
{"path": "/collections/{collectionId}/items/{itemId}", "method": "PUT"},
Expand All @@ -74,7 +74,7 @@ def test_build_api_with_route_dependencies(self):
def test_add_route_dependencies_after_building_api(self):
routes = [
{"path": "/collections", "method": "POST"},
{"path": "/collections", "method": "PUT"},
{"path": "/collections/{collectionId}", "method": "PUT"},
{"path": "/collections/{collectionId}", "method": "DELETE"},
{"path": "/collections/{collectionId}/items", "method": "POST"},
{"path": "/collections/{collectionId}/items/{itemId}", "method": "PUT"},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Transaction extension."""

from typing import List, Optional, Type, Union

import attr
Expand Down Expand Up @@ -117,10 +118,10 @@ def register_create_collection(self):
)

def register_update_collection(self):
"""Register update collection endpoint (PUT /collections)."""
"""Register update collection endpoint (PUT /collections/{collection_id})."""
self.router.add_api_route(
name="Update Collection",
path="/collections",
path="/collections/{collection_id}",
response_model=Collection if self.settings.enable_response_models else None,
response_class=self.response_class,
response_model_exclude_unset=True,
Expand Down
20 changes: 11 additions & 9 deletions stac_fastapi/types/stac_fastapi/types/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Base clients."""

import abc
from typing import Any, Dict, List, Optional, Union
from urllib.parse import urljoin
Expand Down Expand Up @@ -101,18 +102,18 @@ def create_collection(

@abc.abstractmethod
def update_collection(
self, collection: stac_types.Collection, **kwargs
self, collection_id: str, collection: stac_types.Collection, **kwargs
) -> Optional[Union[stac_types.Collection, Response]]:
"""Perform a complete update on an existing collection.
Called with `PUT /collections`. It is expected that this item already
exists. The update should do a diff against the saved collection and
Called with `PUT /collections/{collection_id}`. It is expected that this item
already exists. The update should do a diff against the saved collection and
perform any necessary updates. Partial updates are not supported by the
transactions extension.
Args:
collection: the collection (must be complete)
collection_id: the id of the collection from the resource path
collection_id: id of the existing collection to be updated
collection: the updated collection (must be complete)
Returns:
The updated collection.
Expand Down Expand Up @@ -214,17 +215,18 @@ async def create_collection(

@abc.abstractmethod
async def update_collection(
self, collection: stac_types.Collection, **kwargs
self, collection_id: str, collection: stac_types.Collection, **kwargs
) -> Optional[Union[stac_types.Collection, Response]]:
"""Perform a complete update on an existing collection.
Called with `PUT /collections`. It is expected that this item already
exists. The update should do a diff against the saved collection and
Called with `PUT /collections/{collection_id}`. It is expected that this item
already exists. The update should do a diff against the saved collection and
perform any necessary updates. Partial updates are not supported by the
transactions extension.
Args:
collection: the collection (must be complete)
collection_id: id of the existing collection to be updated
collection: the updated collection (must be complete)
Returns:
The updated collection.
Expand Down

0 comments on commit 6e74b21

Please sign in to comment.