Skip to content

Commit e4e4120

Browse files
use Collection Pydantic model in PutCollection transaction (#679)
* use Collection Pydantic model in PutCollection transaction * update output types
1 parent e7f82d6 commit e4e4120

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
from stac_fastapi.api.models import CollectionUri, ItemUri
1212
from stac_fastapi.api.routes import create_async_endpoint
13-
from stac_fastapi.types import stac
1413
from stac_fastapi.types.config import ApiSettings
1514
from stac_fastapi.types.core import AsyncBaseTransactionsClient, BaseTransactionsClient
1615
from stac_fastapi.types.extension import ApiExtension
@@ -34,7 +33,7 @@ class PutItem(ItemUri):
3433
class PutCollection(CollectionUri):
3534
"""Update Collection."""
3635

37-
collection: stac.Collection = attr.ib(default=Body(None))
36+
collection: Collection = attr.ib(default=Body(None))
3837

3938

4039
@attr.s

stac_fastapi/extensions/tests/test_transaction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Iterator, Union
33

44
import pytest
5+
from stac_pydantic import Collection
56
from stac_pydantic.item import Item
67
from stac_pydantic.item_collection import ItemCollection
78
from starlette.testclient import TestClient
@@ -10,7 +11,6 @@
1011
from stac_fastapi.extensions.core import TransactionExtension
1112
from stac_fastapi.types.config import ApiSettings
1213
from stac_fastapi.types.core import BaseCoreClient, BaseTransactionsClient
13-
from stac_fastapi.types.stac import Collection
1414

1515

1616
class DummyCoreClient(BaseCoreClient):
@@ -56,7 +56,7 @@ def create_collection(self, collection: Collection, **kwargs):
5656
return {"type": collection.type}
5757

5858
def update_collection(self, collection_id: str, collection: Collection, **kwargs):
59-
return {"path_collection_id": collection_id, "type": collection["type"]}
59+
return {"path_collection_id": collection_id, "type": collection.type}
6060

6161
def delete_collection(self, collection_id: str, **kwargs):
6262
return {"path_collection_id": collection_id}

stac_fastapi/types/stac_fastapi/types/core.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def create_item(
3838
collection_id: str,
3939
item: Union[Item, ItemCollection],
4040
**kwargs,
41-
) -> Optional[Union[Item, Response, None]]:
41+
) -> Optional[Union[stac.Item, Response, None]]:
4242
"""Create a new item.
4343
4444
Called with `POST /collections/{collection_id}/items`.
@@ -55,7 +55,7 @@ def create_item(
5555
@abc.abstractmethod
5656
def update_item(
5757
self, collection_id: str, item_id: str, item: Item, **kwargs
58-
) -> Optional[Union[Item, Response]]:
58+
) -> Optional[Union[stac.Item, Response]]:
5959
"""Perform a complete update on an existing item.
6060
6161
Called with `PUT /collections/{collection_id}/items`. It is expected
@@ -75,7 +75,7 @@ def update_item(
7575
@abc.abstractmethod
7676
def delete_item(
7777
self, item_id: str, collection_id: str, **kwargs
78-
) -> Optional[Union[Item, Response]]:
78+
) -> Optional[Union[stac.Item, Response]]:
7979
"""Delete an item from a collection.
8080
8181
Called with `DELETE /collections/{collection_id}/items/{item_id}`
@@ -92,7 +92,7 @@ def delete_item(
9292
@abc.abstractmethod
9393
def create_collection(
9494
self, collection: Collection, **kwargs
95-
) -> Optional[Union[Collection, Response]]:
95+
) -> Optional[Union[stac.Collection, Response]]:
9696
"""Create a new collection.
9797
9898
Called with `POST /collections`.
@@ -108,7 +108,7 @@ def create_collection(
108108
@abc.abstractmethod
109109
def update_collection(
110110
self, collection_id: str, collection: Collection, **kwargs
111-
) -> Optional[Union[Collection, Response]]:
111+
) -> Optional[Union[stac.Collection, Response]]:
112112
"""Perform a complete update on an existing collection.
113113
114114
Called with `PUT /collections/{collection_id}`. It is expected that this
@@ -128,7 +128,7 @@ def update_collection(
128128
@abc.abstractmethod
129129
def delete_collection(
130130
self, collection_id: str, **kwargs
131-
) -> Optional[Union[Collection, Response]]:
131+
) -> Optional[Union[stac.Collection, Response]]:
132132
"""Delete a collection.
133133
134134
Called with `DELETE /collections/{collection_id}`
@@ -152,7 +152,7 @@ async def create_item(
152152
collection_id: str,
153153
item: Union[Item, ItemCollection],
154154
**kwargs,
155-
) -> Optional[Union[Item, Response, None]]:
155+
) -> Optional[Union[stac.Item, Response, None]]:
156156
"""Create a new item.
157157
158158
Called with `POST /collections/{collection_id}/items`.
@@ -169,7 +169,7 @@ async def create_item(
169169
@abc.abstractmethod
170170
async def update_item(
171171
self, collection_id: str, item_id: str, item: Item, **kwargs
172-
) -> Optional[Union[Item, Response]]:
172+
) -> Optional[Union[stac.Item, Response]]:
173173
"""Perform a complete update on an existing item.
174174
175175
Called with `PUT /collections/{collection_id}/items`. It is expected
@@ -188,7 +188,7 @@ async def update_item(
188188
@abc.abstractmethod
189189
async def delete_item(
190190
self, item_id: str, collection_id: str, **kwargs
191-
) -> Optional[Union[Item, Response]]:
191+
) -> Optional[Union[stac.Item, Response]]:
192192
"""Delete an item from a collection.
193193
194194
Called with `DELETE /collections/{collection_id}/items/{item_id}`
@@ -205,7 +205,7 @@ async def delete_item(
205205
@abc.abstractmethod
206206
async def create_collection(
207207
self, collection: Collection, **kwargs
208-
) -> Optional[Union[Collection, Response]]:
208+
) -> Optional[Union[stac.Collection, Response]]:
209209
"""Create a new collection.
210210
211211
Called with `POST /collections`.
@@ -221,7 +221,7 @@ async def create_collection(
221221
@abc.abstractmethod
222222
async def update_collection(
223223
self, collection_id: str, collection: Collection, **kwargs
224-
) -> Optional[Union[Collection, Response]]:
224+
) -> Optional[Union[stac.Collection, Response]]:
225225
"""Perform a complete update on an existing collection.
226226
227227
Called with `PUT /collections/{collection_id}`. It is expected that this item
@@ -241,7 +241,7 @@ async def update_collection(
241241
@abc.abstractmethod
242242
async def delete_collection(
243243
self, collection_id: str, **kwargs
244-
) -> Optional[Union[Collection, Response]]:
244+
) -> Optional[Union[stac.Collection, Response]]:
245245
"""Delete a collection.
246246
247247
Called with `DELETE /collections/{collection_id}`

0 commit comments

Comments
 (0)