From 7351f20dfdc95bafc9cfc5705f749fa68f902540 Mon Sep 17 00:00:00 2001 From: rhysrevans3 Date: Fri, 21 Mar 2025 13:14:11 +0000 Subject: [PATCH 1/2] Use list of objects for assets. --- stac_fastapi/core/stac_fastapi/core/serializers.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/stac_fastapi/core/stac_fastapi/core/serializers.py b/stac_fastapi/core/stac_fastapi/core/serializers.py index 9b0d36d4..22546703 100644 --- a/stac_fastapi/core/stac_fastapi/core/serializers.py +++ b/stac_fastapi/core/stac_fastapi/core/serializers.py @@ -1,4 +1,5 @@ """Serializers.""" + import abc from copy import deepcopy from typing import Any, List, Optional @@ -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 @@ -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", [])}, ) @@ -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 @@ -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) From a2648a390f285f1e924a39a71007bdb8a3d18b02 Mon Sep 17 00:00:00 2001 From: rhysrevans3 Date: Fri, 21 Mar 2025 14:45:39 +0000 Subject: [PATCH 2/2] Fix update item test failure. --- stac_fastapi/core/stac_fastapi/core/core.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/stac_fastapi/core/stac_fastapi/core/core.py b/stac_fastapi/core/stac_fastapi/core/core.py index 56afcbc8..dd9c9897 100644 --- a/stac_fastapi/core/stac_fastapi/core/core.py +++ b/stac_fastapi/core/stac_fastapi/core/core.py @@ -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. @@ -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( pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy