use dioxus::prelude::*; use serde::{Deserialize, Serialize}; use compliance_core::models::TrackedRepository; #[derive(Debug, Clone, Serialize, Deserialize, Default)] pub struct RepositoryListResponse { pub data: Vec, pub total: Option, pub page: Option, } #[server] pub async fn fetch_repositories(page: u64) -> Result { let state: super::server_state::ServerState = dioxus_fullstack::FullstackContext::extract().await?; let url = format!("{}/api/v1/repositories?page={page}&limit=20", state.agent_api_url); let resp = reqwest::get(&url).await.map_err(|e| ServerFnError::new(e.to_string()))?; let body: RepositoryListResponse = resp.json().await.map_err(|e| ServerFnError::new(e.to_string()))?; Ok(body) } #[server] pub async fn add_repository(name: String, git_url: String, default_branch: String) -> Result<(), ServerFnError> { let state: super::server_state::ServerState = dioxus_fullstack::FullstackContext::extract().await?; let url = format!("{}/api/v1/repositories", state.agent_api_url); let client = reqwest::Client::new(); let resp = client .post(&url) .json(&serde_json::json!({ "name": name, "git_url": git_url, "default_branch": default_branch, })) .send() .await .map_err(|e| ServerFnError::new(e.to_string()))?; if !resp.status().is_success() { let body = resp.text().await.unwrap_or_default(); return Err(ServerFnError::new(format!("Failed to add repository: {body}"))); } Ok(()) } #[server] pub async fn trigger_repo_scan(repo_id: String) -> Result<(), ServerFnError> { let state: super::server_state::ServerState = dioxus_fullstack::FullstackContext::extract().await?; let url = format!("{}/api/v1/repositories/{repo_id}/scan", state.agent_api_url); let client = reqwest::Client::new(); client .post(&url) .send() .await .map_err(|e| ServerFnError::new(e.to_string()))?; Ok(()) }