Skip to content

Commit 20ac8d9

Browse files
committed
create find collection
1 parent e2d2f28 commit 20ac8d9

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,7 @@ def get_all_collections(self, base_url: str) -> Collections:
6767

6868
def get_one_collection(self, collection_id: str) -> Collection:
6969
"""Database logic to retrieve a single collection."""
70-
try:
71-
collection = self.client.get(index=COLLECTIONS_INDEX, id=collection_id)
72-
except elasticsearch.exceptions.NotFoundError:
73-
raise NotFoundError(f"Collection {collection_id} not found")
74-
70+
collection = self.find_collection(collection_id=collection_id)
7571
return collection["_source"]
7672

7773
def get_item_collection(
@@ -287,19 +283,22 @@ def create_collection(self, collection: stac_types.Collection):
287283
document=collection,
288284
)
289285

290-
def prep_update_collection(self, collection_id: str):
291-
"""Database logic for prepping a collection for updating."""
286+
def find_collection(self, collection_id: str) -> stac_types.Collection:
287+
"""Database logic to find and return a collection."""
292288
try:
293-
_ = self.client.get(index=COLLECTIONS_INDEX, id=collection_id)
289+
collection = self.client.get(index=COLLECTIONS_INDEX, id=collection_id)
294290
except elasticsearch.exceptions.NotFoundError:
295291
raise NotFoundError(f"Collection {collection_id} not found")
296292

293+
return collection
294+
295+
def prep_update_collection(self, collection_id: str):
296+
"""Database logic for prepping a collection for updating."""
297+
_ = self.find_collection(collection_id=collection_id)
298+
297299
def delete_collection(self, collection_id: str):
298300
"""Database logic for deleting one collection."""
299-
try:
300-
_ = self.client.get(index=COLLECTIONS_INDEX, id=collection_id)
301-
except elasticsearch.exceptions.NotFoundError:
302-
raise NotFoundError(f"Collection {collection_id} not found")
301+
_ = self.find_collection(collection_id=collection_id)
303302
self.client.delete(index=COLLECTIONS_INDEX, id=collection_id)
304303

305304
def bulk_sync(self, processed_items):

0 commit comments

Comments
 (0)