File tree Expand file tree Collapse file tree 3 files changed +52
-2
lines changed
Expand file tree Collapse file tree 3 files changed +52
-2
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,21 @@ async def import_scenario_data(
127127 log .info (f'PUT /scenarios/{ scenarioId } received...' )
128128 return await controller .import_scenario_data (scenarioId , file )
129129
130+ @router .put (
131+ "/scenarios/{scenarioId}/description" ,
132+ responses = {
133+ 200 : {"model" : ReducedScenario , "description" : "Updated description of scenario." },
134+ },
135+ tags = ["Scenarios" ],
136+ response_model_by_alias = True ,
137+ )
138+ async def update_scenario_description (
139+ scenarioId : StrictStr = Path (..., description = "UUID of the scenario" ),
140+ description : StrictStr = Body (..., description = "New description for the scenario" )
141+ ) -> ReducedScenario :
142+ """Update description of a scenario."""
143+ log .info (f'PUT /scenarios/{ scenarioId } received...' )
144+ return await controller .update_scenario_description (scenarioId , description )
130145
131146@router .get (
132147 "/scenarios" ,
Original file line number Diff line number Diff line change 4040 group_get_all ,
4141 compartment_get_all ,
4242 node_get_by_list ,
43- datapoint_update_all_by_scenario
43+ datapoint_update_all_by_scenario ,
44+ scenario_update_description
4445)
4546
4647class LookupObject :
@@ -283,4 +284,12 @@ async def _read_percentiles(
283284 percentile = percentile ,
284285 value = value
285286 ))
286- return datapoints
287+ return datapoints
288+
289+ async def update_scenario_description (
290+ self ,
291+ scenarioId : StrictStr ,
292+ description : StrictStr ,
293+ ) -> ReducedScenario :
294+ """Update description of a scenario."""
295+ return scenario_update_description (scenarioId , description )
Original file line number Diff line number Diff line change @@ -661,3 +661,29 @@ def datapoint_update_all_by_scenario(
661661 session .add (scenario )
662662 session .commit ()
663663 return
664+
665+
666+ def scenario_update_description (
667+ scenarioId : StrictStr ,
668+ description : StrictStr
669+ ) -> ID :
670+ query = select (db .Scenario ).where (db .Scenario .id == scenarioId )
671+ with next (get_session ()) as session :
672+ scenario : db .Scenario = session .exec (query ).one_or_none ()
673+ if not scenario :
674+ raise HTTPException (status_code = 404 , detail = 'A scenario with this ID does not exist' )
675+
676+ scenario .description = description
677+ session .add (scenario )
678+ session .commit ()
679+ session .refresh (scenario )
680+ return ReducedScenario (
681+ id = str (scenario .id ),
682+ name = scenario .name ,
683+ description = scenario .description ,
684+ startDate = scenario .startDate ,
685+ endDate = scenario .endDate ,
686+ percentiles = [int (perc ) for perc in scenario .percentiles .split (',' )],
687+ timestampSubmitted = scenario .timestampSubmitted ,
688+ timestampSimulated = scenario .timestampSimulated ,
689+ )
You can’t perform that action at this time.
0 commit comments