Skip to content

Commit f2b2b52

Browse files
committed
normalize styling
1 parent a2e4f3a commit f2b2b52

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ def index_by_collection_id(collection_id: str) -> str:
131131
Translate a collection id into an Elasticsearch index name.
132132
133133
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.
135135
136136
Returns:
137-
- str: The index name derived from the collection id.
137+
str: The index name derived from the collection id.
138138
"""
139139
return f"{ITEMS_INDEX_PREFIX}{collection_id}"
140140

@@ -144,10 +144,10 @@ def indices(collection_ids: Optional[List[str]]) -> str:
144144
Get a comma-separated string of index names for a given list of collection ids.
145145
146146
Args:
147-
collection_ids: A list of collection ids.
147+
collection_ids: A list of collection ids.
148148
149149
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.
151151
"""
152152
if collection_ids is None:
153153
return DEFAULT_INDICES
@@ -176,10 +176,10 @@ async def create_item_index(collection_id: str):
176176
Create the index for Items.
177177
178178
Args:
179-
- collection_id (str): Collection identifier.
179+
collection_id (str): Collection identifier.
180180
181181
Returns:
182-
None
182+
None
183183
184184
"""
185185
client = AsyncElasticsearchSettings().create_client
@@ -555,7 +555,20 @@ async def check_collection_exists(self, collection_id: str):
555555
raise NotFoundError(f"Collection {collection_id} does not exist")
556556

557557
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+
"""
559572
await self.check_collection_exists(collection_id=item["collection"])
560573

561574
if await self.client.exists(
@@ -569,7 +582,24 @@ async def prep_create_item(self, item: Item, base_url: str) -> Item:
569582
return self.item_serializer.stac_to_db(item, base_url)
570583

571584
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+
"""
573603
item_id = item["id"]
574604
collection_id = item["collection"]
575605
if not self.sync_client.exists(index=COLLECTIONS_INDEX, id=collection_id):

0 commit comments

Comments
 (0)