|
6 | 6 |
|
7 | 7 | from app.api.dependencies import admin_user |
8 | 8 | from app.domain.enums.replay import ReplayStatus |
9 | | -from app.domain.replay import ReplayConfig, ReplaySessionState |
| 9 | +from app.domain.replay import ReplayConfig |
10 | 10 | from app.schemas_pydantic.replay import ( |
11 | 11 | CleanupResponse, |
12 | 12 | ReplayRequest, |
|
16 | 16 | from app.schemas_pydantic.replay_models import ReplaySession |
17 | 17 | from app.services.replay_service import ReplayService |
18 | 18 |
|
19 | | - |
20 | | -def _session_to_summary(state: ReplaySessionState) -> SessionSummary: |
21 | | - """Convert ReplaySessionState to SessionSummary.""" |
22 | | - state_data = asdict(state) |
23 | | - state_data.update(state_data.pop("config")) # flatten config fields |
24 | | - |
25 | | - duration = None |
26 | | - throughput = None |
27 | | - if state.started_at and state.completed_at: |
28 | | - duration = (state.completed_at - state.started_at).total_seconds() |
29 | | - if state.replayed_events > 0 and duration > 0: |
30 | | - throughput = state.replayed_events / duration |
31 | | - |
32 | | - return SessionSummary(**state_data, duration_seconds=duration, throughput_events_per_second=throughput) |
33 | | - |
34 | | - |
35 | 19 | router = APIRouter(prefix="/replay", tags=["Event Replay"], route_class=DishkaRoute, dependencies=[Depends(admin_user)]) |
36 | 20 |
|
37 | 21 |
|
@@ -80,8 +64,10 @@ async def list_replay_sessions( |
80 | 64 | status: ReplayStatus | None = Query(None), |
81 | 65 | limit: int = Query(100, ge=1, le=1000), |
82 | 66 | ) -> list[SessionSummary]: |
83 | | - states = service.list_sessions(status=status, limit=limit) |
84 | | - return [_session_to_summary(s) for s in states] |
| 67 | + return [ |
| 68 | + SessionSummary.model_validate({**asdict(s), **asdict(s)["config"]}) |
| 69 | + for s in service.list_sessions(status=status, limit=limit) |
| 70 | + ] |
85 | 71 |
|
86 | 72 |
|
87 | 73 | @router.get("/sessions/{session_id}", response_model=ReplaySession) |
|
0 commit comments