feat: implement CRUD APIs for projects and scenarios with validated schemas
This commit is contained in:
@@ -35,7 +35,8 @@ class ProjectRepository:
|
||||
try:
|
||||
self.session.flush()
|
||||
except IntegrityError as exc: # pragma: no cover - reliance on DB constraints
|
||||
raise EntityConflictError("Project violates uniqueness constraints") from exc
|
||||
raise EntityConflictError(
|
||||
"Project violates uniqueness constraints") from exc
|
||||
return project
|
||||
|
||||
def delete(self, project_id: int) -> None:
|
||||
@@ -64,7 +65,10 @@ class ScenarioRepository:
|
||||
joinedload(Scenario.financial_inputs),
|
||||
joinedload(Scenario.simulation_parameters),
|
||||
)
|
||||
scenario = self.session.execute(stmt).scalar_one_or_none()
|
||||
result = self.session.execute(stmt)
|
||||
if with_children:
|
||||
result = result.unique()
|
||||
scenario = result.scalar_one_or_none()
|
||||
if scenario is None:
|
||||
raise EntityNotFoundError(f"Scenario {scenario_id} not found")
|
||||
return scenario
|
||||
@@ -102,7 +106,8 @@ class FinancialInputRepository:
|
||||
try:
|
||||
self.session.flush()
|
||||
except IntegrityError as exc: # pragma: no cover
|
||||
raise EntityConflictError("Financial input violates constraints") from exc
|
||||
raise EntityConflictError(
|
||||
"Financial input violates constraints") from exc
|
||||
return entities
|
||||
|
||||
def delete(self, input_id: int) -> None:
|
||||
@@ -135,12 +140,15 @@ class SimulationParameterRepository:
|
||||
try:
|
||||
self.session.flush()
|
||||
except IntegrityError as exc: # pragma: no cover
|
||||
raise EntityConflictError("Simulation parameter violates constraints") from exc
|
||||
raise EntityConflictError(
|
||||
"Simulation parameter violates constraints") from exc
|
||||
return entities
|
||||
|
||||
def delete(self, parameter_id: int) -> None:
|
||||
stmt = select(SimulationParameter).where(SimulationParameter.id == parameter_id)
|
||||
stmt = select(SimulationParameter).where(
|
||||
SimulationParameter.id == parameter_id)
|
||||
entity = self.session.execute(stmt).scalar_one_or_none()
|
||||
if entity is None:
|
||||
raise EntityNotFoundError(f"Simulation parameter {parameter_id} not found")
|
||||
raise EntityNotFoundError(
|
||||
f"Simulation parameter {parameter_id} not found")
|
||||
self.session.delete(entity)
|
||||
|
||||
Reference in New Issue
Block a user