@@ -82,7 +82,7 @@ def get_item_collection(
82
82
search = search .query (collection_filter )
83
83
84
84
count = self .search_count (search )
85
-
85
+
86
86
# search = search.sort({"id.keyword" : {"order" : "asc"}})
87
87
search = search .query ()[0 :limit ]
88
88
collection_children = search .execute ().to_dict ()
@@ -230,10 +230,14 @@ def execute_search(self, search, limit: int, base_url: str) -> List:
230
230
231
231
# Transaction Logic
232
232
233
- def prep_create_item (self , item : stac_types .Item , base_url : str ):
233
+ def check_collection_exists (self , collection_id : str ):
234
+ """Database logic to check if a collection exists."""
235
+ if not self .client .exists (index = COLLECTIONS_INDEX , id = collection_id ):
236
+ raise ForeignKeyError (f"Collection { collection_id } does not exist" )
237
+
238
+ def prep_create_item (self , item : stac_types .Item , base_url : str ) -> stac_types .Item :
234
239
"""Database logic for prepping an item for insertion."""
235
- if not self .client .exists (index = COLLECTIONS_INDEX , id = item ["collection" ]):
236
- raise ForeignKeyError (f"Collection { item ['collection' ]} does not exist" )
240
+ self .check_collection_exists (collection_id = item ["collection" ])
237
241
238
242
if self .client .exists (
239
243
index = ITEMS_INDEX , id = mk_item_id (item ["id" ], item ["collection" ])
@@ -260,8 +264,7 @@ def create_item(self, item: stac_types.Item, base_url: str):
260
264
261
265
def prep_update_item (self , item : stac_types .Item ):
262
266
"""Database logic for prepping an item for updating."""
263
- if not self .client .exists (index = COLLECTIONS_INDEX , id = item ["collection" ]):
264
- raise ForeignKeyError (f"Collection { item ['collection' ]} does not exist" )
267
+ self .check_collection_exists (collection_id = item ["collection" ])
265
268
266
269
def delete_item (self , item_id : str , collection_id : str ):
267
270
"""Database logic for deleting one item."""
0 commit comments