Repository: stac-utils/stac-fastapi
Pull request #631 (2024-02-14 09:12:37)

Update collection update endpoint.
**Related Issue(s):**

- #630

**Description:**

Updating the collection update endpoint to match to the [collection-transaction extension](https://github.com/stac-api-extensions/collection-transaction).

**PR Checklist:**

- [x] `pre-commit` hooks pass locally
- [x] Tests pass (run `make test`)
- [x] Documentation has been updated to reflect changes, if applicable, and docs build successfully (run `make docs`)
- [x] Changes are added to the [CHANGELOG](https://github.com/stac-utils/stac-fastapi/blob/main/CHANGES.md).



Patch:
diff --git a/CHANGES.md b/CHANGES.md
index 9f4525d..5ed1cc9 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -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))
diff --git a/Makefile b/Makefile
index 517b9b9..e802fbb 100644
--- a/Makefile
+++ b/Makefile
@@ -18,3 +18,7 @@ docs-image:
 docs: docs-image
 	docker-compose -f docker-compose.docs.yml \
 		run docs
+
+.PHONY: test
+test: image
+	pytest .
\ No newline at end of file
diff --git a/stac_fastapi/extensions/stac_fastapi/extensions/core/transaction.py b/stac_fastapi/extensions/stac_fastapi/extensions/core/transaction.py
index 480ff09..0ebcc61 100644
--- a/stac_fastapi/extensions/stac_fastapi/extensions/core/transaction.py
+++ b/stac_fastapi/extensions/stac_fastapi/extensions/core/transaction.py
@@ -1,4 +1,5 @@
 """Transaction extension."""
+
 from typing import List, Optional, Type, Union
 
 import attr
@@ -117,10 +118,10 @@ class TransactionExtension(ApiExtension):
         )
 
     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,
diff --git a/stac_fastapi/types/stac_fastapi/types/core.py b/stac_fastapi/types/stac_fastapi/types/core.py
index bc48732..79b18f5 100644
--- a/stac_fastapi/types/stac_fastapi/types/core.py
+++ b/stac_fastapi/types/stac_fastapi/types/core.py
@@ -1,4 +1,5 @@
 """Base clients."""
+
 import abc
 from typing import Any, Dict, List, Optional, Union
 from urllib.parse import urljoin
@@ -101,18 +102,18 @@ class BaseTransactionsClient(abc.ABC):
 
     @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.
@@ -214,17 +215,18 @@ class AsyncBaseTransactionsClient(abc.ABC):
 
     @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.


Test patch:
diff --git a/stac_fastapi/api/tests/test_api.py b/stac_fastapi/api/tests/test_api.py
index ce49cef..91b5037 100644
--- a/stac_fastapi/api/tests/test_api.py
+++ b/stac_fastapi/api/tests/test_api.py
@@ -61,7 +61,7 @@ class TestRouteDependencies:
     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"},
@@ -74,7 +74,7 @@ class TestRouteDependencies:
     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"},