Skip to content

Commit

Permalink
Adds a query param that expands incident pagination to return the ful…
Browse files Browse the repository at this point in the history
…ly populated object (#2938)

* Adds a query param that expands incident pagination to return the fully populated object

* Remove default api call
  • Loading branch information
kevgliss authored Feb 2, 2023
1 parent 178aa05 commit 38744b7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
7 changes: 7 additions & 0 deletions src/dispatch/incident/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,13 @@ class IncidentRead(IncidentBase):
workflow_instances: Optional[List[WorkflowInstanceRead]] = []


class IncidentExpandedPagination(DispatchBase):
total: int
itemsPerPage: int
page: int
items: List[IncidentRead] = []


class IncidentPagination(DispatchBase):
total: int
itemsPerPage: int
Expand Down
27 changes: 18 additions & 9 deletions src/dispatch/incident/views.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import calendar
import json
import logging

from datetime import date
from dateutil.relativedelta import relativedelta
from typing import List

from starlette.requests import Request
from dateutil.relativedelta import relativedelta
from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException, Query, status

from sqlalchemy.orm import Session
from starlette.requests import Request

from dispatch.auth.models import DispatchUser
from dispatch.auth.permissions import (
IncidentEditPermission,
IncidentJoinOrSubscribePermission,
IncidentViewPermission,
PermissionsDependency,
)
from dispatch.auth.models import DispatchUser
from dispatch.auth.service import get_current_user
from dispatch.common.utils.views import create_pydantic_include
from dispatch.database.core import get_db
Expand All @@ -27,7 +25,7 @@
from dispatch.models import OrganizationSlug, PrimaryKey
from dispatch.participant.models import ParticipantUpdate
from dispatch.report import flows as report_flows
from dispatch.report.models import TacticalReportCreate, ExecutiveReportCreate
from dispatch.report.models import ExecutiveReportCreate, TacticalReportCreate

from .flows import (
incident_add_or_reactivate_participant_flow,
Expand All @@ -37,11 +35,17 @@
incident_create_stable_flow,
incident_update_flow,
)
from .metrics import make_forecast, create_incident_metric_query
from .models import Incident, IncidentCreate, IncidentPagination, IncidentRead, IncidentUpdate
from .metrics import create_incident_metric_query, make_forecast
from .models import (
Incident,
IncidentCreate,
IncidentExpandedPagination,
IncidentPagination,
IncidentRead,
IncidentUpdate,
)
from .service import create, delete, get, update


log = logging.getLogger(__name__)

router = APIRouter()
Expand All @@ -63,10 +67,15 @@ def get_incidents(
*,
common: dict = Depends(common_parameters),
include: List[str] = Query([], alias="include[]"),
expand: bool = Query(default=False),
):
"""Retrieves a list of incidents."""
print(expand)
pagination = search_filter_sort_paginate(model="Incident", **common)

if expand:
return json.loads(IncidentExpandedPagination(**pagination).json())

if include:
# only allow two levels for now
include_sets = create_pydantic_include(include)
Expand Down

0 comments on commit 38744b7

Please sign in to comment.