From bd13359d01d2d83d4cb1481c8abaa668d6c7f37f Mon Sep 17 00:00:00 2001 From: MaxBetz <104758467+MaxBetzDLR@users.noreply.github.com> Date: Thu, 6 Nov 2025 14:27:40 +0000 Subject: [PATCH] Add functions for update of description --- api/src/api/app/apis/scenarios_api.py | 15 +++++++++++++++ .../api/app/controller/scenario_controller.py | 13 +++++++++++-- api/src/api/app/db/tasks.py | 16 ++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/api/src/api/app/apis/scenarios_api.py b/api/src/api/app/apis/scenarios_api.py index 42ccfab..6768119 100644 --- a/api/src/api/app/apis/scenarios_api.py +++ b/api/src/api/app/apis/scenarios_api.py @@ -127,6 +127,21 @@ async def import_scenario_data( log.info(f'PUT /scenarios/{scenarioId} received...') return await controller.import_scenario_data(scenarioId, file) +@router.put( + "/scenarios/{scenarioId}", + responses={ + 0: {"model": ID, "description": "Updated description of scenario."}, + }, + tags=["Scenarios"], + response_model_by_alias=True, +) +async def update_scenario_description( + scenarioId: StrictStr = Path(..., description="UUID of the scenario"), + description: StrictStr = Body(..., description="New description for the scenario") +) -> ID: + """Update description of a scenario.""" + log.info(f'PUT /scenarios/{scenarioId} received...') + return await controller.update_scenario_description(scenarioId, description) @router.get( "/scenarios", diff --git a/api/src/api/app/controller/scenario_controller.py b/api/src/api/app/controller/scenario_controller.py index 92eb620..71a2e73 100644 --- a/api/src/api/app/controller/scenario_controller.py +++ b/api/src/api/app/controller/scenario_controller.py @@ -40,7 +40,8 @@ group_get_all, compartment_get_all, node_get_by_list, - datapoint_update_all_by_scenario + datapoint_update_all_by_scenario, + scenario_update_description ) class LookupObject: @@ -283,4 +284,12 @@ async def _read_percentiles( percentile=percentile, value=value )) - return datapoints \ No newline at end of file + return datapoints + + async def update_scenario_description( + self, + scenarioId: StrictStr, + description: StrictStr, + ) -> ID: + """Update description of a scenario.""" + return scenario_update_description(scenarioId, description) \ No newline at end of file diff --git a/api/src/api/app/db/tasks.py b/api/src/api/app/db/tasks.py index e7b4deb..52d5c24 100644 --- a/api/src/api/app/db/tasks.py +++ b/api/src/api/app/db/tasks.py @@ -661,3 +661,19 @@ def datapoint_update_all_by_scenario( session.add(scenario) session.commit() return + + +def scenario_update_description( + scenarioId: StrictStr, + description: StrictStr +) -> ID: + query = select(db.Scenario).where(db.Scenario.id == scenarioId) + with next(get_session()) as session: + scenario: db.Scenario = session.exec(query).one_or_none() + if not scenario: + raise HTTPException(status_code=404, detail='A scenario with this ID does not exist') + + scenario.description = description + session.add(scenario) + session.commit() + return ID(id=scenarioId)