Skip to content

Commit 9fb89c1

Browse files
committed
Web-API
- Fixed E-NAUTILUS endpoints to work with the new SessionContextGuard.
1 parent 15ad48b commit 9fb89c1

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

desdeo/api/routers/enautilus.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@
3636
@router.post("/step")
3737
def step(
3838
request: ENautilusStepRequest,
39-
context: Annotated[
40-
SessionContext,
41-
Depends(SessionContextGuard(require=[ContextField.PROBLEM]))
42-
],
39+
context: Annotated[SessionContext, Depends(SessionContextGuard(require=[ContextField.PROBLEM]))],
4340
) -> ENautilusStepResponse:
4441
"""Steps the E-NAUTILUS method."""
4542
db_session = context.db_session
@@ -244,7 +241,10 @@ def get_representative(
244241
@router.post("/finalize")
245242
def finalize_enautilus(
246243
request: ENautilusFinalizeRequest,
247-
context: Annotated[SessionContext, Depends(get_session_context)],
244+
context: Annotated[
245+
SessionContext,
246+
Depends(SessionContextGuard(require=[ContextField.PROBLEM, ContextField.PARENT_STATE])),
247+
],
248248
) -> ENautilusFinalizeResponse:
249249
"""Finalize E-NAUTILUS by selecting the final solution.
250250
@@ -362,8 +362,7 @@ def finalize_enautilus(
362362

363363
@router.get("/session_tree/{session_id}")
364364
def get_session_tree(
365-
session_id: int,
366-
db_session: Annotated[Session, Depends(get_session)],
365+
session_id: int, context: Annotated[SessionContext, Depends(SessionContextGuard())]
367366
) -> ENautilusSessionTreeResponse:
368367
"""Extract the full E-NAUTILUS decision tree for a session.
369368
@@ -372,11 +371,13 @@ def get_session_tree(
372371
373372
Args:
374373
session_id: The interactive session ID.
375-
db_session: The database session.
374+
context: The context of the query.
376375
377376
Returns:
378377
ENautilusSessionTreeResponse with nodes, edges, root_ids, and decision_events.
379378
"""
379+
db_session = context.db_session
380+
380381
# Query step states
381382
step_stmt = (
382383
select(StateDB)

desdeo/api/routers/problem.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def get_problem(
109109
"""
110110
return context.problem_db
111111

112+
112113
@router.post("/add")
113114
def add_problem(
114115
request: Annotated[Problem, Depends(parse_problem_json)],
@@ -445,7 +446,7 @@ def delete_representative_solution_set(
445446
@router.delete("/{problem_id}", status_code=status.HTTP_204_NO_CONTENT)
446447
def delete_problem(
447448
problem_id: int,
448-
context: Annotated[SessionContext, Depends(get_session_context_without_request)],
449+
context: Annotated[SessionContext, Depends(SessionContextGuard())],
449450
):
450451
"""Delete a problem by its ID."""
451452
db_session: Session = context.db_session
@@ -465,7 +466,7 @@ def delete_problem(
465466
@router.get("/{problem_id}/json")
466467
def get_problem_json(
467468
problem_id: int,
468-
context: Annotated[SessionContext, Depends(get_session_context_without_request)],
469+
context: Annotated[SessionContext, Depends(SessionContextGuard())],
469470
) -> JSONResponse:
470471
"""Return a Problem as a serialized JSON object suitable for download/re-upload."""
471472
db_session: Session = context.db_session

0 commit comments

Comments
 (0)