use crate::connection::MDRSConnection; pub use crate::models::folder::{FolderDetail, FolderSimple}; use anyhow::bail; impl MDRSConnection { /// List folders matching the given path under a laboratory (GET v3/folders/?path=...&laboratory_id=...) pub async fn list_folders_by_path( &self, lab_id: u32, path: &str, ) -> Result, anyhow::Error> { let params = [ ("laboratory_id", lab_id.to_string()), ("path", path.to_string()), ]; let resp = self.get_with_query("v3/folders/", ¶ms).await?; if !resp.status().is_success() { bail!("List folders failed: {}", resp.status()); } Ok(resp.json::>().await?) } /// Retrieve full folder details including sub_folders (GET v3/folders/{id}/) pub async fn retrieve_folder(&self, id: &str) -> Result { let resp = self.get(&format!("v3/folders/{}/", id)).await?; if !resp.status().is_success() { bail!("Retrieve folder failed: {}", resp.status()); } Ok(resp.json::().await?) } /// Create a new folder under `parent_id` (POST v3/folders/). pub async fn create_folder( &self, parent_id: &str, folder_name: &str, ) -> Result { let body = serde_json::json!({ "name": folder_name, "parent_id": parent_id, "description": "", "template_id": -1, }); self.post_json("v3/folders/", &body).await } /// Authenticate against a password-locked folder (POST v3/folders/{id}/auth/). /// Returns `Err` if the password is incorrect or the request fails. pub async fn folder_auth(&self, folder_id: &str, password: &str) -> Result<(), anyhow::Error> { let resp = self .post_json( &format!("v3/folders/{}/auth/", folder_id), &serde_json::json!({"password": password}), ) .await?; if resp.status() == reqwest::StatusCode::UNAUTHORIZED { bail!("Password is incorrect."); } if !resp.status().is_success() { bail!("Folder auth failed: {}", resp.status()); } Ok(()) } }