Skip to content

Commit 827c68a

Browse files
committed
remove uneeded code
1 parent 7770152 commit 827c68a

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/core.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ def all_collections(self, **kwargs) -> Collections:
7272
def get_collection(self, collection_id: str, **kwargs) -> Collection:
7373
"""Get collection by id."""
7474
base_url = str(kwargs["request"].base_url)
75-
collection = self.database.get_one_collection(collection_id)
75+
collection = self.database.find_collection(collection_id=collection_id)[
76+
"_source"
77+
]
7678
return self.collection_serializer.db_to_stac(collection, base_url)
7779

7880
@overrides

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from stac_fastapi.elasticsearch import serializers
1111
from stac_fastapi.elasticsearch.config import ElasticsearchSettings
12-
from stac_fastapi.types import stac as stac_types
1312
from stac_fastapi.types.errors import ConflictError, ForeignKeyError, NotFoundError
1413
from stac_fastapi.types.stac import Collection, Collections, Item, ItemCollection
1514

@@ -65,11 +64,6 @@ def get_all_collections(self, base_url: str) -> Collections:
6564

6665
return serialized_collections
6766

68-
def get_one_collection(self, collection_id: str) -> Collection:
69-
"""Database logic to retrieve a single collection."""
70-
collection = self.find_collection(collection_id=collection_id)
71-
return collection["_source"]
72-
7367
def get_item_collection(
7468
self, collection_id: str, limit: int, base_url: str
7569
) -> ItemCollection:
@@ -235,7 +229,7 @@ def check_collection_exists(self, collection_id: str):
235229
if not self.client.exists(index=COLLECTIONS_INDEX, id=collection_id):
236230
raise ForeignKeyError(f"Collection {collection_id} does not exist")
237231

238-
def prep_create_item(self, item: stac_types.Item, base_url: str) -> stac_types.Item:
232+
def prep_create_item(self, item: Item, base_url: str) -> Item:
239233
"""Database logic for prepping an item for insertion."""
240234
self.check_collection_exists(collection_id=item["collection"])
241235

@@ -248,7 +242,7 @@ def prep_create_item(self, item: stac_types.Item, base_url: str) -> stac_types.I
248242

249243
return self.item_serializer.stac_to_db(item, base_url)
250244

251-
def create_item(self, item: stac_types.Item, base_url: str):
245+
def create_item(self, item: Item, base_url: str):
252246
"""Database logic for creating one item."""
253247
# todo: check if collection exists, but cache
254248
es_resp = self.client.index(
@@ -262,10 +256,6 @@ def create_item(self, item: stac_types.Item, base_url: str):
262256
f"Item {item['id']} in collection {item['collection']} already exists"
263257
)
264258

265-
def prep_update_item(self, item: stac_types.Item):
266-
"""Database logic for prepping an item for updating."""
267-
self.check_collection_exists(collection_id=item["collection"])
268-
269259
def delete_item(self, item_id: str, collection_id: str):
270260
"""Database logic for deleting one item."""
271261
try:
@@ -275,7 +265,7 @@ def delete_item(self, item_id: str, collection_id: str):
275265
f"Item {item_id} in collection {collection_id} not found"
276266
)
277267

278-
def create_collection(self, collection: stac_types.Collection):
268+
def create_collection(self, collection: Collection):
279269
"""Database logic for creating one collection."""
280270
if self.client.exists(index=COLLECTIONS_INDEX, id=collection["id"]):
281271
raise ConflictError(f"Collection {collection['id']} already exists")
@@ -286,7 +276,7 @@ def create_collection(self, collection: stac_types.Collection):
286276
document=collection,
287277
)
288278

289-
def find_collection(self, collection_id: str) -> stac_types.Collection:
279+
def find_collection(self, collection_id: str) -> Collection:
290280
"""Database logic to find and return a collection."""
291281
try:
292282
collection = self.client.get(index=COLLECTIONS_INDEX, id=collection_id)
@@ -295,10 +285,6 @@ def find_collection(self, collection_id: str) -> stac_types.Collection:
295285

296286
return collection
297287

298-
def prep_update_collection(self, collection_id: str):
299-
"""Database logic for prepping a collection for updating."""
300-
_ = self.find_collection(collection_id=collection_id)
301-
302288
def delete_collection(self, collection_id: str):
303289
"""Database logic for deleting one collection."""
304290
_ = self.find_collection(collection_id=collection_id)

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/transactions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def update_item(self, item: stac_types.Item, **kwargs) -> stac_types.Item:
5656
now = datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
5757
item["properties"]["updated"] = str(now)
5858

59-
self.database.prep_update_item(item=item)
59+
self.database.check_collection_exists(collection_id=item["collection"])
6060
# todo: index instead of delete and create
6161
self.delete_item(item_id=item["id"], collection_id=item["collection"])
6262
self.create_item(item=item, **kwargs)
@@ -92,7 +92,7 @@ def update_collection(
9292
"""Update collection."""
9393
base_url = str(kwargs["request"].base_url)
9494

95-
self.database.prep_update_collection(collection_id=collection["id"])
95+
self.database.find_collection(collection_id=collection["id"])
9696
self.delete_collection(collection["id"])
9797
self.create_collection(collection, **kwargs)
9898

0 commit comments

Comments
 (0)