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 1/3] 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) From 6c544ab0aa85834ceeefe4d3946d660752ced068 Mon Sep 17 00:00:00 2001 From: MaxBetz <104758467+MaxBetzDLR@users.noreply.github.com> Date: Mon, 8 Dec 2025 14:53:01 +0100 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Moritz Zeumer <25636783+NXXR@users.noreply.github.com> --- api/src/api/app/apis/scenarios_api.py | 4 ++-- api/src/api/app/controller/scenario_controller.py | 2 +- api/src/api/app/db/tasks.py | 12 +++++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/api/src/api/app/apis/scenarios_api.py b/api/src/api/app/apis/scenarios_api.py index 6768119..0ec2e70 100644 --- a/api/src/api/app/apis/scenarios_api.py +++ b/api/src/api/app/apis/scenarios_api.py @@ -130,7 +130,7 @@ async def import_scenario_data( @router.put( "/scenarios/{scenarioId}", responses={ - 0: {"model": ID, "description": "Updated description of scenario."}, + 200: {"model": ReducedScenario, "description": "Updated description of scenario."}, }, tags=["Scenarios"], response_model_by_alias=True, @@ -138,7 +138,7 @@ async def import_scenario_data( async def update_scenario_description( scenarioId: StrictStr = Path(..., description="UUID of the scenario"), description: StrictStr = Body(..., description="New description for the scenario") -) -> ID: +) -> ReducedScenario: """Update description of a scenario.""" log.info(f'PUT /scenarios/{scenarioId} received...') return await controller.update_scenario_description(scenarioId, description) diff --git a/api/src/api/app/controller/scenario_controller.py b/api/src/api/app/controller/scenario_controller.py index 71a2e73..907989d 100644 --- a/api/src/api/app/controller/scenario_controller.py +++ b/api/src/api/app/controller/scenario_controller.py @@ -290,6 +290,6 @@ async def update_scenario_description( self, scenarioId: StrictStr, description: StrictStr, - ) -> ID: + ) -> ReducedScenario: """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 52d5c24..46aa754 100644 --- a/api/src/api/app/db/tasks.py +++ b/api/src/api/app/db/tasks.py @@ -676,4 +676,14 @@ def scenario_update_description( scenario.description = description session.add(scenario) session.commit() - return ID(id=scenarioId) + session.refresh(scenario) + return ReducedScenario( + id=str(scenario.id), + name=scenario.name, + description=scenario.description, + startDate=scenario.startDate, + endDate=scenario.endDate, + percentiles=[int(perc) for perc in scenario.percentiles.split(',')], + timestampSubmitted=scenario.timestampSubmitted, + timestampSimulated=scenario.timestampSimulated, + ) From 6a105f401c8d644f2fa298554c0dda0a193abe9d Mon Sep 17 00:00:00 2001 From: "Zeumer, Moritz" Date: Wed, 10 Dec 2025 10:47:50 +0100 Subject: [PATCH 3/3] change endpoint name to avoid overlap --- api/src/api/app/apis/scenarios_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/api/app/apis/scenarios_api.py b/api/src/api/app/apis/scenarios_api.py index 0ec2e70..ef84da9 100644 --- a/api/src/api/app/apis/scenarios_api.py +++ b/api/src/api/app/apis/scenarios_api.py @@ -128,7 +128,7 @@ async def import_scenario_data( return await controller.import_scenario_data(scenarioId, file) @router.put( - "/scenarios/{scenarioId}", + "/scenarios/{scenarioId}/description", responses={ 200: {"model": ReducedScenario, "description": "Updated description of scenario."}, },