@@ -131,10 +131,10 @@ def index_by_collection_id(collection_id: str) -> str:
131
131
Translate a collection id into an Elasticsearch index name.
132
132
133
133
Args:
134
- - collection_id (str): The collection id to translate into an index name.
134
+ collection_id (str): The collection id to translate into an index name.
135
135
136
136
Returns:
137
- - str: The index name derived from the collection id.
137
+ str: The index name derived from the collection id.
138
138
"""
139
139
return f"{ ITEMS_INDEX_PREFIX } { collection_id } "
140
140
@@ -144,10 +144,10 @@ def indices(collection_ids: Optional[List[str]]) -> str:
144
144
Get a comma-separated string of index names for a given list of collection ids.
145
145
146
146
Args:
147
- collection_ids: A list of collection ids.
147
+ collection_ids: A list of collection ids.
148
148
149
149
Returns:
150
- A string of comma-separated index names. If `collection_ids` is None, returns the default indices.
150
+ A string of comma-separated index names. If `collection_ids` is None, returns the default indices.
151
151
"""
152
152
if collection_ids is None :
153
153
return DEFAULT_INDICES
@@ -176,10 +176,10 @@ async def create_item_index(collection_id: str):
176
176
Create the index for Items.
177
177
178
178
Args:
179
- - collection_id (str): Collection identifier.
179
+ collection_id (str): Collection identifier.
180
180
181
181
Returns:
182
- None
182
+ None
183
183
184
184
"""
185
185
client = AsyncElasticsearchSettings ().create_client
@@ -555,7 +555,20 @@ async def check_collection_exists(self, collection_id: str):
555
555
raise NotFoundError (f"Collection { collection_id } does not exist" )
556
556
557
557
async def prep_create_item (self , item : Item , base_url : str ) -> Item :
558
- """Database logic for prepping an item for insertion."""
558
+ """
559
+ Preps an item for insertion into the database.
560
+
561
+ Args:
562
+ item (Item): The item to be prepped for insertion.
563
+ base_url (str): The base URL used to create the item's self URL.
564
+
565
+ Returns:
566
+ Item: The prepped item.
567
+
568
+ Raises:
569
+ ConflictError: If the item already exists in the database.
570
+
571
+ """
559
572
await self .check_collection_exists (collection_id = item ["collection" ])
560
573
561
574
if await self .client .exists (
@@ -569,7 +582,24 @@ async def prep_create_item(self, item: Item, base_url: str) -> Item:
569
582
return self .item_serializer .stac_to_db (item , base_url )
570
583
571
584
def sync_prep_create_item (self , item : Item , base_url : str ) -> Item :
572
- """Database logic for prepping an item for insertion."""
585
+ """
586
+ Prepare an item for insertion into the database.
587
+
588
+ This method performs pre-insertion preparation on the given `item`,
589
+ such as checking if the collection the item belongs to exists,
590
+ and verifying that an item with the same ID does not already exist in the database.
591
+
592
+ Args:
593
+ item (Item): The item to be inserted into the database.
594
+ base_url (str): The base URL used for constructing URLs for the item.
595
+
596
+ Returns:
597
+ Item: The item after preparation is done.
598
+
599
+ Raises:
600
+ NotFoundError: If the collection that the item belongs to does not exist in the database.
601
+ ConflictError: If an item with the same ID already exists in the collection.
602
+ """
573
603
item_id = item ["id" ]
574
604
collection_id = item ["collection" ]
575
605
if not self .sync_client .exists (index = COLLECTIONS_INDEX , id = collection_id ):
0 commit comments