All checks were successful
CI / Format (push) Successful in 4s
CI / Clippy (push) Successful in 4m19s
CI / Security Audit (push) Successful in 1m44s
CI / Detect Changes (push) Successful in 5s
CI / Tests (push) Successful in 5m15s
CI / Deploy Agent (push) Successful in 2s
CI / Deploy Dashboard (push) Successful in 2s
CI / Deploy Docs (push) Has been skipped
CI / Deploy MCP (push) Successful in 2s
38 lines
957 B
Rust
38 lines
957 B
Rust
use axum::extract::{Extension, Query};
|
|
use axum::Json;
|
|
use mongodb::bson::doc;
|
|
|
|
use super::dto::*;
|
|
use compliance_core::models::ScanRun;
|
|
|
|
#[tracing::instrument(skip_all)]
|
|
pub async fn list_scan_runs(
|
|
Extension(agent): AgentExt,
|
|
Query(params): Query<PaginationParams>,
|
|
) -> ApiResult<Vec<ScanRun>> {
|
|
let db = &agent.db;
|
|
let skip = (params.page.saturating_sub(1)) * params.limit as u64;
|
|
let total = db.scan_runs().count_documents(doc! {}).await.unwrap_or(0);
|
|
|
|
let scans = match db
|
|
.scan_runs()
|
|
.find(doc! {})
|
|
.sort(doc! { "started_at": -1 })
|
|
.skip(skip)
|
|
.limit(params.limit)
|
|
.await
|
|
{
|
|
Ok(cursor) => collect_cursor_async(cursor).await,
|
|
Err(e) => {
|
|
tracing::warn!("Failed to fetch scan runs: {e}");
|
|
Vec::new()
|
|
}
|
|
};
|
|
|
|
Ok(Json(ApiResponse {
|
|
data: scans,
|
|
total: Some(total),
|
|
page: Some(params.page),
|
|
}))
|
|
}
|