Skip to content

Update collection update endpoint. #631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
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