Skip to content

Commit

Permalink
add collection deletion to uploader
Browse files Browse the repository at this point in the history
  • Loading branch information
jdries committed Sep 18, 2024
1 parent b7c4410 commit b8ff5a6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 6 additions & 6 deletions stacbuilder/stacapi/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def create_or_update(self, collection: Collection) -> dict:
else:
return self.create(collection)

def delete(self, collection: Collection) -> dict:
def delete(self, collection: Collection):
"""Delete this collection.
:param collection: pystac.Collection object to delete from the STAC API backend.
Expand All @@ -296,7 +296,7 @@ def delete(self, collection: Collection) -> dict:
"""
return self.delete_by_id(collection.id)

def delete_by_id(self, collection_id: str) -> dict:
def delete_by_id(self, collection_id: str):
"""Delete the collection that has the specified ID.
:param collection_id: the collection ID to look for.
Expand All @@ -314,7 +314,7 @@ def delete_by_id(self, collection_id: str) -> dict:

response = self._rest_api.delete(f"collections/{collection_id}")
_check_response_status(response, _EXPECTED_STATUS_DELETE)
return response.json()


def _add_authentication_section(self, collection: Collection) -> dict:
coll_dict = collection.to_dict()
Expand Down Expand Up @@ -445,7 +445,7 @@ def create_or_update(self, item: Item) -> dict:
else:
return self.create(item)

def delete_by_id(self, collection_id: str, item_id: str) -> dict:
def delete_by_id(self, collection_id: str, item_id: str):
if not collection_id:
raise ValueError(
"collection_id must have a non-empty str value."
Expand All @@ -461,9 +461,9 @@ def delete_by_id(self, collection_id: str, item_id: str) -> dict:
print(f"HTTP response: {response.status_code} - {response.reason}: body: {response.json()}")

_check_response_status(response, _EXPECTED_STATUS_DELETE)
return response.json()

def delete_item(self, item: Item) -> dict:

def delete_item(self, item: Item):
if not item.collection_id:
raise InvalidOperation(
"Can not delete item: item.collection_id must be a non-empty str value."
Expand Down
3 changes: 3 additions & 0 deletions stacbuilder/stacapi/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ def bulk_size(self) -> int:
def bulk_size(self, value: int) -> int:
self._bulk_size = int(value)

def delete_collection(self, id:str) :
return self._collections_endpoint.delete_by_id(id)

def upload_collection(self, collection: Path | Collection) -> dict:
if isinstance(collection, Path):
collection = Collection.from_file(collection)
Expand Down

0 comments on commit b8ff5a6

Please sign in to comment.