From e4e4120ae6d1a9fe80910073af5889ae08c418f8 Mon Sep 17 00:00:00 2001 From: Vincent Sarago Date: Thu, 2 May 2024 10:19:41 +0200 Subject: [PATCH] use Collection Pydantic model in PutCollection transaction (#679) * use Collection Pydantic model in PutCollection transaction * update output types --- .../extensions/core/transaction.py | 3 +-- .../extensions/tests/test_transaction.py | 4 ++-- stac_fastapi/types/stac_fastapi/types/core.py | 24 +++++++++---------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/stac_fastapi/extensions/stac_fastapi/extensions/core/transaction.py b/stac_fastapi/extensions/stac_fastapi/extensions/core/transaction.py index 818315e1..67b6260a 100644 --- a/stac_fastapi/extensions/stac_fastapi/extensions/core/transaction.py +++ b/stac_fastapi/extensions/stac_fastapi/extensions/core/transaction.py @@ -10,7 +10,6 @@ from stac_fastapi.api.models import CollectionUri, ItemUri from stac_fastapi.api.routes import create_async_endpoint -from stac_fastapi.types import stac from stac_fastapi.types.config import ApiSettings from stac_fastapi.types.core import AsyncBaseTransactionsClient, BaseTransactionsClient from stac_fastapi.types.extension import ApiExtension @@ -34,7 +33,7 @@ class PutItem(ItemUri): class PutCollection(CollectionUri): """Update Collection.""" - collection: stac.Collection = attr.ib(default=Body(None)) + collection: Collection = attr.ib(default=Body(None)) @attr.s diff --git a/stac_fastapi/extensions/tests/test_transaction.py b/stac_fastapi/extensions/tests/test_transaction.py index d686d8f9..689e519d 100644 --- a/stac_fastapi/extensions/tests/test_transaction.py +++ b/stac_fastapi/extensions/tests/test_transaction.py @@ -2,6 +2,7 @@ from typing import Iterator, Union import pytest +from stac_pydantic import Collection from stac_pydantic.item import Item from stac_pydantic.item_collection import ItemCollection from starlette.testclient import TestClient @@ -10,7 +11,6 @@ from stac_fastapi.extensions.core import TransactionExtension from stac_fastapi.types.config import ApiSettings from stac_fastapi.types.core import BaseCoreClient, BaseTransactionsClient -from stac_fastapi.types.stac import Collection class DummyCoreClient(BaseCoreClient): @@ -56,7 +56,7 @@ def create_collection(self, collection: Collection, **kwargs): return {"type": collection.type} def update_collection(self, collection_id: str, collection: Collection, **kwargs): - return {"path_collection_id": collection_id, "type": collection["type"]} + return {"path_collection_id": collection_id, "type": collection.type} def delete_collection(self, collection_id: str, **kwargs): return {"path_collection_id": collection_id} diff --git a/stac_fastapi/types/stac_fastapi/types/core.py b/stac_fastapi/types/stac_fastapi/types/core.py index d0dc029f..fdf020b0 100644 --- a/stac_fastapi/types/stac_fastapi/types/core.py +++ b/stac_fastapi/types/stac_fastapi/types/core.py @@ -38,7 +38,7 @@ def create_item( collection_id: str, item: Union[Item, ItemCollection], **kwargs, - ) -> Optional[Union[Item, Response, None]]: + ) -> Optional[Union[stac.Item, Response, None]]: """Create a new item. Called with `POST /collections/{collection_id}/items`. @@ -55,7 +55,7 @@ def create_item( @abc.abstractmethod def update_item( self, collection_id: str, item_id: str, item: Item, **kwargs - ) -> Optional[Union[Item, Response]]: + ) -> Optional[Union[stac.Item, Response]]: """Perform a complete update on an existing item. Called with `PUT /collections/{collection_id}/items`. It is expected @@ -75,7 +75,7 @@ def update_item( @abc.abstractmethod def delete_item( self, item_id: str, collection_id: str, **kwargs - ) -> Optional[Union[Item, Response]]: + ) -> Optional[Union[stac.Item, Response]]: """Delete an item from a collection. Called with `DELETE /collections/{collection_id}/items/{item_id}` @@ -92,7 +92,7 @@ def delete_item( @abc.abstractmethod def create_collection( self, collection: Collection, **kwargs - ) -> Optional[Union[Collection, Response]]: + ) -> Optional[Union[stac.Collection, Response]]: """Create a new collection. Called with `POST /collections`. @@ -108,7 +108,7 @@ def create_collection( @abc.abstractmethod def update_collection( self, collection_id: str, collection: Collection, **kwargs - ) -> Optional[Union[Collection, Response]]: + ) -> Optional[Union[stac.Collection, Response]]: """Perform a complete update on an existing collection. Called with `PUT /collections/{collection_id}`. It is expected that this @@ -128,7 +128,7 @@ def update_collection( @abc.abstractmethod def delete_collection( self, collection_id: str, **kwargs - ) -> Optional[Union[Collection, Response]]: + ) -> Optional[Union[stac.Collection, Response]]: """Delete a collection. Called with `DELETE /collections/{collection_id}` @@ -152,7 +152,7 @@ async def create_item( collection_id: str, item: Union[Item, ItemCollection], **kwargs, - ) -> Optional[Union[Item, Response, None]]: + ) -> Optional[Union[stac.Item, Response, None]]: """Create a new item. Called with `POST /collections/{collection_id}/items`. @@ -169,7 +169,7 @@ async def create_item( @abc.abstractmethod async def update_item( self, collection_id: str, item_id: str, item: Item, **kwargs - ) -> Optional[Union[Item, Response]]: + ) -> Optional[Union[stac.Item, Response]]: """Perform a complete update on an existing item. Called with `PUT /collections/{collection_id}/items`. It is expected @@ -188,7 +188,7 @@ async def update_item( @abc.abstractmethod async def delete_item( self, item_id: str, collection_id: str, **kwargs - ) -> Optional[Union[Item, Response]]: + ) -> Optional[Union[stac.Item, Response]]: """Delete an item from a collection. Called with `DELETE /collections/{collection_id}/items/{item_id}` @@ -205,7 +205,7 @@ async def delete_item( @abc.abstractmethod async def create_collection( self, collection: Collection, **kwargs - ) -> Optional[Union[Collection, Response]]: + ) -> Optional[Union[stac.Collection, Response]]: """Create a new collection. Called with `POST /collections`. @@ -221,7 +221,7 @@ async def create_collection( @abc.abstractmethod async def update_collection( self, collection_id: str, collection: Collection, **kwargs - ) -> Optional[Union[Collection, Response]]: + ) -> Optional[Union[stac.Collection, Response]]: """Perform a complete update on an existing collection. Called with `PUT /collections/{collection_id}`. It is expected that this item @@ -241,7 +241,7 @@ async def update_collection( @abc.abstractmethod async def delete_collection( self, collection_id: str, **kwargs - ) -> Optional[Union[Collection, Response]]: + ) -> Optional[Union[stac.Collection, Response]]: """Delete a collection. Called with `DELETE /collections/{collection_id}`