use dioxus::prelude::*; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize, Default)] pub struct NotificationListResponse { pub data: Vec, #[serde(default)] pub total: Option, } #[derive(Debug, Clone, Serialize, Deserialize, Default)] pub struct CveNotificationData { #[serde(rename = "_id")] pub id: Option, pub cve_id: String, pub repo_name: String, pub package_name: String, pub package_version: String, pub severity: String, pub cvss_score: Option, pub summary: Option, pub url: Option, pub status: String, #[serde(default)] pub created_at: Option, } #[derive(Debug, Clone, Serialize, Deserialize, Default)] pub struct NotificationCountResponse { pub count: u64, } #[server] pub async fn fetch_notification_count() -> Result { let state: super::server_state::ServerState = dioxus_fullstack::FullstackContext::extract().await?; let url = format!("{}/api/v1/notifications/count", state.agent_api_url); let resp = reqwest::get(&url) .await .map_err(|e| ServerFnError::new(e.to_string()))?; let body: NotificationCountResponse = resp .json() .await .map_err(|e| ServerFnError::new(e.to_string()))?; Ok(body.count) } #[server] pub async fn fetch_notifications() -> Result { let state: super::server_state::ServerState = dioxus_fullstack::FullstackContext::extract().await?; let url = format!("{}/api/v1/notifications?limit=20", state.agent_api_url); let resp = reqwest::get(&url) .await .map_err(|e| ServerFnError::new(e.to_string()))?; let body: NotificationListResponse = resp .json() .await .map_err(|e| ServerFnError::new(e.to_string()))?; Ok(body) } #[server] pub async fn mark_all_notifications_read() -> Result<(), ServerFnError> { let state: super::server_state::ServerState = dioxus_fullstack::FullstackContext::extract().await?; let url = format!("{}/api/v1/notifications/read-all", state.agent_api_url); reqwest::Client::new() .post(&url) .send() .await .map_err(|e| ServerFnError::new(e.to_string()))?; Ok(()) } #[server] pub async fn dismiss_notification(id: String) -> Result<(), ServerFnError> { let state: super::server_state::ServerState = dioxus_fullstack::FullstackContext::extract().await?; let url = format!("{}/api/v1/notifications/{id}/dismiss", state.agent_api_url); reqwest::Client::new() .patch(&url) .send() .await .map_err(|e| ServerFnError::new(e.to_string()))?; Ok(()) }