Skip to content

Commit

Permalink
feat(api): complete deletion methods
Browse files Browse the repository at this point in the history
  • Loading branch information
salemsd committed Jan 8, 2025
1 parent 4372266 commit 1d1fe3e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/antares/craft/exceptions/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ def __init__(self, study_id: str, message: str) -> None:
self.message = f"Could not get outputs for {study_id}: " + message
super().__init__(self.message)

class OutputDeletionError(Exception):
def __init__(self, study_id: str, output_name:str, message: str) -> None:
self.message = f"Could not delete the output {output_name} from study {study_id}: " + message
super().__init__(self.message)


class AggregateCreationError(Exception):
def __init__(self, study_id: str, output_id: str, mc_type: str, object_type: str, message: str) -> None:
Expand Down
2 changes: 2 additions & 0 deletions src/antares/craft/model/study.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,11 @@ def get_output(self, output_id: str) -> Output:

def delete_outputs(self) -> None:
self._study_service.delete_outputs()
self._outputs.clear()

def delete_output(self, output_name: str) -> None:
self._study_service.delete_output(output_name)
self._outputs.pop(output_name)

def _verify_study_already_exists(study_directory: Path) -> None:
if study_directory.exists():
Expand Down
18 changes: 15 additions & 3 deletions src/antares/craft/service/api_services/study_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
OutputsRetrievalError,
StudyDeletionError,
StudySettingsUpdateError,
StudyVariantCreationError,
StudyVariantCreationError, OutputDeletionError,
)
from antares.craft.model.binding_constraint import BindingConstraint
from antares.craft.model.output import Output
Expand Down Expand Up @@ -143,7 +143,19 @@ def read_outputs(self) -> list[Output]:
raise OutputsRetrievalError(self.study_id, e.message)

def delete_outputs(self) -> None:
pass
outputs_url = f"{self._base_url}/studies/{self.study_id}/outputs"
try:
response = self._wrapper.get(outputs_url)
outputs_json_list = response.json()
for output in outputs_json_list:
output_name = output["name"]
self.delete_output(output_name)
except APIError as e:
raise OutputsRetrievalError(self.study_id, e.message)

def delete_output(self, output_name: str) -> None:
pass
url = f"{self._base_url}/studies/{self.study_id}/outputs/{output_name}"
try:
self._wrapper.delete(url)
except APIError as e:
raise OutputDeletionError(self.study_id, output_name, e.message) from e

0 comments on commit 1d1fe3e

Please sign in to comment.