Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.

Commit 38744b7

Browse files
authored
Adds a query param that expands incident pagination to return the fully populated object (#2938)
* Adds a query param that expands incident pagination to return the fully populated object * Remove default api call
1 parent 178aa05 commit 38744b7

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

src/dispatch/incident/models.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,13 @@ class IncidentRead(IncidentBase):
361361
workflow_instances: Optional[List[WorkflowInstanceRead]] = []
362362

363363

364+
class IncidentExpandedPagination(DispatchBase):
365+
total: int
366+
itemsPerPage: int
367+
page: int
368+
items: List[IncidentRead] = []
369+
370+
364371
class IncidentPagination(DispatchBase):
365372
total: int
366373
itemsPerPage: int

src/dispatch/incident/views.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
import calendar
22
import json
33
import logging
4-
54
from datetime import date
6-
from dateutil.relativedelta import relativedelta
75
from typing import List
86

9-
from starlette.requests import Request
7+
from dateutil.relativedelta import relativedelta
108
from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException, Query, status
11-
129
from sqlalchemy.orm import Session
10+
from starlette.requests import Request
1311

12+
from dispatch.auth.models import DispatchUser
1413
from dispatch.auth.permissions import (
1514
IncidentEditPermission,
1615
IncidentJoinOrSubscribePermission,
1716
IncidentViewPermission,
1817
PermissionsDependency,
1918
)
20-
from dispatch.auth.models import DispatchUser
2119
from dispatch.auth.service import get_current_user
2220
from dispatch.common.utils.views import create_pydantic_include
2321
from dispatch.database.core import get_db
@@ -27,7 +25,7 @@
2725
from dispatch.models import OrganizationSlug, PrimaryKey
2826
from dispatch.participant.models import ParticipantUpdate
2927
from dispatch.report import flows as report_flows
30-
from dispatch.report.models import TacticalReportCreate, ExecutiveReportCreate
28+
from dispatch.report.models import ExecutiveReportCreate, TacticalReportCreate
3129

3230
from .flows import (
3331
incident_add_or_reactivate_participant_flow,
@@ -37,11 +35,17 @@
3735
incident_create_stable_flow,
3836
incident_update_flow,
3937
)
40-
from .metrics import make_forecast, create_incident_metric_query
41-
from .models import Incident, IncidentCreate, IncidentPagination, IncidentRead, IncidentUpdate
38+
from .metrics import create_incident_metric_query, make_forecast
39+
from .models import (
40+
Incident,
41+
IncidentCreate,
42+
IncidentExpandedPagination,
43+
IncidentPagination,
44+
IncidentRead,
45+
IncidentUpdate,
46+
)
4247
from .service import create, delete, get, update
4348

44-
4549
log = logging.getLogger(__name__)
4650

4751
router = APIRouter()
@@ -63,10 +67,15 @@ def get_incidents(
6367
*,
6468
common: dict = Depends(common_parameters),
6569
include: List[str] = Query([], alias="include[]"),
70+
expand: bool = Query(default=False),
6671
):
6772
"""Retrieves a list of incidents."""
73+
print(expand)
6874
pagination = search_filter_sort_paginate(model="Incident", **common)
6975

76+
if expand:
77+
return json.loads(IncidentExpandedPagination(**pagination).json())
78+
7079
if include:
7180
# only allow two levels for now
7281
include_sets = create_pydantic_include(include)

0 commit comments

Comments
 (0)