Skip to content

Unique asset names #341

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
9 changes: 4 additions & 5 deletions stac_fastapi/core/stac_fastapi/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ async def get_item(

@staticmethod
def _return_date(
interval: Optional[Union[DateTimeType, str]]
interval: Optional[Union[DateTimeType, str]],
) -> Dict[str, Optional[str]]:
"""
Convert a date interval.
Expand Down Expand Up @@ -724,15 +724,14 @@ async def update_item(

"""
item = item.model_dump(mode="json")
base_url = str(kwargs["request"].base_url)
now = datetime_type.now(timezone.utc).isoformat().replace("+00:00", "Z")
item["properties"]["updated"] = now

await self.database.check_collection_exists(collection_id)
await self.delete_item(item_id=item_id, collection_id=collection_id)
await self.create_item(collection_id=collection_id, item=Item(**item), **kwargs)

return ItemSerializer.db_to_stac(item, base_url)
return await self.create_item(
collection_id=collection_id, item=Item(**item), **kwargs
)

@overrides
async def delete_item(
Expand Down
14 changes: 13 additions & 1 deletion stac_fastapi/core/stac_fastapi/core/serializers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Serializers."""

import abc
from copy import deepcopy
from typing import Any, List, Optional
Expand Down Expand Up @@ -65,6 +66,10 @@ def stac_to_db(cls, stac_data: stac_types.Item, base_url: str) -> stac_types.Ite
item_links = resolve_links(stac_data.get("links", []), base_url)
stac_data["links"] = item_links

stac_data["assets"] = [
{"es_key": k, **v} for k, v in stac_data.get("assets", {}).items()
]

now = now_to_rfc3339_str()
if "created" not in stac_data["properties"]:
stac_data["properties"]["created"] = now
Expand Down Expand Up @@ -102,7 +107,7 @@ def db_to_stac(cls, item: dict, base_url: str) -> stac_types.Item:
bbox=item.get("bbox", []),
properties=item.get("properties", {}),
links=item_links,
assets=item.get("assets", {}),
assets={a.pop("es_key"): a for a in item.get("assets", [])},
)


Expand All @@ -127,6 +132,9 @@ def stac_to_db(
collection["links"] = resolve_links(
collection.get("links", []), str(request.base_url)
)
collection["assets"] = [
{"es_key": k, **v} for k, v in collection.get("assets", {}).items()
]
return collection

@classmethod
Expand Down Expand Up @@ -173,5 +181,9 @@ def db_to_stac(
collection_links += resolve_links(original_links, str(request.base_url))
collection["links"] = collection_links

collection["assets"] = {
a.pop("es_key"): a for a in collection.get("assets", [])
}

# Return the stac_types.Collection object
return stac_types.Collection(**collection)