11"""Serializers."""
2+
23import abc
34from copy import deepcopy
45from 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
6566 item_links = resolve_links (stac_data .get ("links" , []), base_url )
6667 stac_data ["links" ] = item_links
6768
69+ stac_data ["assets" ] = [
70+ {"es_key" : k , ** v } for k , v in stac_data .get ("assets" , {}).items ()
71+ ]
72+
6873 now = now_to_rfc3339_str ()
6974 if "created" not in stac_data ["properties" ]:
7075 stac_data ["properties" ]["created" ] = now
@@ -102,7 +107,7 @@ def db_to_stac(cls, item: dict, base_url: str) -> stac_types.Item:
102107 bbox = item .get ("bbox" , []),
103108 properties = item .get ("properties" , {}),
104109 links = item_links ,
105- assets = item .get ("assets" , {}) ,
110+ assets = { a . pop ( "es_key" ): a for a in item .get ("assets" , [])} ,
106111 )
107112
108113
@@ -127,6 +132,9 @@ def stac_to_db(
127132 collection ["links" ] = resolve_links (
128133 collection .get ("links" , []), str (request .base_url )
129134 )
135+ collection ["assets" ] = [
136+ {"es_key" : k , ** v } for k , v in collection .get ("assets" , {}).items ()
137+ ]
130138 return collection
131139
132140 @classmethod
@@ -173,5 +181,9 @@ def db_to_stac(
173181 collection_links += resolve_links (original_links , str (request .base_url ))
174182 collection ["links" ] = collection_links
175183
184+ collection ["assets" ] = {
185+ a .pop ("es_key" ): a for a in collection .get ("assets" , [])
186+ }
187+
176188 # Return the stac_types.Collection object
177189 return stac_types .Collection (** collection )
0 commit comments