Skip to content

Commit

Permalink
use Collection Pydantic model in PutCollection transaction (#679)
Browse files Browse the repository at this point in the history
* use Collection Pydantic model in PutCollection transaction

* update output types
  • Loading branch information
vincentsarago authored May 2, 2024
1 parent e7f82d6 commit e4e4120
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions stac_fastapi/extensions/tests/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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}
Expand Down
24 changes: 12 additions & 12 deletions stac_fastapi/types/stac_fastapi/types/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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
Expand All @@ -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}`
Expand All @@ -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`.
Expand All @@ -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
Expand All @@ -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}`
Expand All @@ -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`.
Expand All @@ -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
Expand All @@ -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}`
Expand All @@ -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`.
Expand All @@ -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
Expand All @@ -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}`
Expand Down

0 comments on commit e4e4120

Please sign in to comment.