Skip to content
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

use Collection Pydantic model in PutCollection transaction #679

Merged
merged 2 commits into from
May 2, 2024
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
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))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonhealy1 I'm not sure why but when we use this class (attr) we don't get the validation/serialization 😬

from stac_fastapi.extensions.core.transaction import PutCollection

>>> PutCollection(collection_id='yo', collection={})
PutCollection(collection_id='yo', collection={})

>>> print(type(PutCollection(collection_id='yo', collection={}).collection))
<class 'dict'>

you may have seen this also in the elastic search backend



@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]]:
vincentsarago marked this conversation as resolved.
Show resolved Hide resolved
"""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