Skip to content

Commit

Permalink
chore: Update list_alerts_endpoint to include total count of alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorwalton committed Aug 19, 2024
1 parent e640f57 commit 80593f0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 2 additions & 3 deletions backend/app/incidents/routes/db_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
from app.incidents.schema.db_operations import UpdateCaseStatus
from app.incidents.services.db_operations import add_alert_title_name
from app.incidents.services.db_operations import add_asset_name
from app.incidents.services.db_operations import add_field_name
from app.incidents.services.db_operations import add_field_name, alert_total
from app.incidents.services.db_operations import add_timefield_name
from app.incidents.services.db_operations import create_alert, get_customer_code_names, delete_customer_code_name
from app.incidents.services.db_operations import create_alert_context
Expand Down Expand Up @@ -377,8 +377,7 @@ async def list_alerts_endpoint(
page_size: int = Query(25, ge=1),
db: AsyncSession = Depends(get_db)
):
alerts = await list_alerts(db, page=page, page_size=page_size)
return AlertOutResponse(alerts=alerts, total=len(alerts), success=True, message="Alerts retrieved successfully")
return AlertOutResponse(alerts=await list_alerts(db, page=page, page_size=page_size), total=await alert_total(db), success=True, message="Alerts retrieved successfully")

@incidents_db_operations_router.get("/alert/{alert_id}", response_model=AlertOutResponse)
async def get_alert_by_id_endpoint(alert_id: int, db: AsyncSession = Depends(get_db)):
Expand Down
4 changes: 4 additions & 0 deletions backend/app/incidents/services/db_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
from app.incidents.schema.db_operations import UpdateAlertStatus
from app.incidents.schema.db_operations import UpdateCaseStatus

async def alert_total(db: AsyncSession) -> int:
result = await db.execute(select(Alert))
return len(result.scalars().all())


async def validate_source_exists(source: str, session: AsyncSession):
# Check each of the FieldName tables and ensure each contains at least one entry for the source
Expand Down

0 comments on commit 80593f0

Please sign in to comment.