Some checks failed
CI / Format (pull_request) Successful in 4s
CI / Clippy (push) Failing after 2m48s
CI / Detect Changes (pull_request) Has been skipped
CI / Detect Changes (push) Has been skipped
CI / Deploy Agent (pull_request) Has been skipped
CI / Deploy Dashboard (pull_request) Has been skipped
CI / Deploy Agent (push) Has been skipped
CI / Deploy Dashboard (push) Has been skipped
CI / Deploy Docs (push) Has been skipped
CI / Deploy MCP (push) Has been skipped
CI / Clippy (pull_request) Failing after 2m34s
CI / Security Audit (pull_request) Has been skipped
CI / Tests (pull_request) Has been skipped
CI / Format (push) Successful in 3s
CI / Security Audit (push) Has been skipped
CI / Tests (push) Has been skipped
CI / Deploy Docs (pull_request) Has been skipped
CI / Deploy MCP (pull_request) Has been skipped
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
138 lines
4.0 KiB
Rust
138 lines
4.0 KiB
Rust
use dioxus::prelude::*;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use compliance_core::models::Finding;
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
|
pub struct FindingsListResponse {
|
|
pub data: Vec<Finding>,
|
|
pub total: Option<u64>,
|
|
pub page: Option<u64>,
|
|
}
|
|
|
|
#[server]
|
|
#[allow(clippy::too_many_arguments)]
|
|
pub async fn fetch_findings(
|
|
page: u64,
|
|
severity: String,
|
|
scan_type: String,
|
|
status: String,
|
|
repo_id: String,
|
|
q: String,
|
|
sort_by: String,
|
|
sort_order: String,
|
|
) -> Result<FindingsListResponse, ServerFnError> {
|
|
let state: super::server_state::ServerState =
|
|
dioxus_fullstack::FullstackContext::extract().await?;
|
|
|
|
let mut url = format!(
|
|
"{}/api/v1/findings?page={page}&limit=20",
|
|
state.agent_api_url
|
|
);
|
|
if !severity.is_empty() {
|
|
url.push_str(&format!("&severity={severity}"));
|
|
}
|
|
if !scan_type.is_empty() {
|
|
url.push_str(&format!("&scan_type={scan_type}"));
|
|
}
|
|
if !status.is_empty() {
|
|
url.push_str(&format!("&status={status}"));
|
|
}
|
|
if !repo_id.is_empty() {
|
|
url.push_str(&format!("&repo_id={repo_id}"));
|
|
}
|
|
if !q.is_empty() {
|
|
url.push_str(&format!(
|
|
"&q={}",
|
|
url::form_urlencoded::byte_serialize(q.as_bytes()).collect::<String>()
|
|
));
|
|
}
|
|
if !sort_by.is_empty() {
|
|
url.push_str(&format!("&sort_by={sort_by}"));
|
|
}
|
|
if !sort_order.is_empty() {
|
|
url.push_str(&format!("&sort_order={sort_order}"));
|
|
}
|
|
|
|
let resp = reqwest::get(&url)
|
|
.await
|
|
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
|
let body: FindingsListResponse = resp
|
|
.json()
|
|
.await
|
|
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
|
Ok(body)
|
|
}
|
|
|
|
#[server]
|
|
pub async fn fetch_finding_detail(id: String) -> Result<Finding, ServerFnError> {
|
|
let state: super::server_state::ServerState =
|
|
dioxus_fullstack::FullstackContext::extract().await?;
|
|
let url = format!("{}/api/v1/findings/{id}", state.agent_api_url);
|
|
|
|
let resp = reqwest::get(&url)
|
|
.await
|
|
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
|
let body: serde_json::Value = resp
|
|
.json()
|
|
.await
|
|
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
|
let finding: Finding = serde_json::from_value(body["data"].clone())
|
|
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
|
Ok(finding)
|
|
}
|
|
|
|
#[server]
|
|
pub async fn update_finding_status(id: String, status: String) -> Result<(), ServerFnError> {
|
|
let state: super::server_state::ServerState =
|
|
dioxus_fullstack::FullstackContext::extract().await?;
|
|
let url = format!("{}/api/v1/findings/{id}/status", state.agent_api_url);
|
|
|
|
let client = reqwest::Client::new();
|
|
client
|
|
.patch(&url)
|
|
.json(&serde_json::json!({ "status": status }))
|
|
.send()
|
|
.await
|
|
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[server]
|
|
pub async fn bulk_update_finding_status(
|
|
ids: Vec<String>,
|
|
status: String,
|
|
) -> Result<(), ServerFnError> {
|
|
let state: super::server_state::ServerState =
|
|
dioxus_fullstack::FullstackContext::extract().await?;
|
|
let url = format!("{}/api/v1/findings/bulk-status", state.agent_api_url);
|
|
|
|
let client = reqwest::Client::new();
|
|
client
|
|
.patch(&url)
|
|
.json(&serde_json::json!({ "ids": ids, "status": status }))
|
|
.send()
|
|
.await
|
|
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[server]
|
|
pub async fn update_finding_feedback(id: String, feedback: String) -> Result<(), ServerFnError> {
|
|
let state: super::server_state::ServerState =
|
|
dioxus_fullstack::FullstackContext::extract().await?;
|
|
let url = format!("{}/api/v1/findings/{id}/feedback", state.agent_api_url);
|
|
|
|
let client = reqwest::Client::new();
|
|
client
|
|
.patch(&url)
|
|
.json(&serde_json::json!({ "feedback": feedback }))
|
|
.send()
|
|
.await
|
|
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
|
|
|
Ok(())
|
|
}
|