Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions api/src/api/app/apis/scenarios_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 11 additions & 2 deletions api/src/api/app/controller/scenario_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -283,4 +284,12 @@ async def _read_percentiles(
percentile=percentile,
value=value
))
return datapoints
return datapoints

async def update_scenario_description(
self,
scenarioId: StrictStr,
description: StrictStr,
) -> ID:
"""Update description of a scenario."""
return scenario_update_description(scenarioId, description)
16 changes: 16 additions & 0 deletions api/src/api/app/db/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)