use tauri::State; use crate::db::Database; use super::service::VariableService; use super::types::{CreateVariableInput, ResolvedVariable, UpdateVariableInput, Variable}; #[tauri::command] pub fn get_variable(db: State, id: String) -> Result { let service = VariableService::new(db.inner().clone()); service.get(&id).map_err(|e| e.to_string()) } #[tauri::command] pub fn get_global_variables(db: State) -> Result, String> { let service = VariableService::new(db.inner().clone()); service.get_global().map_err(|e| e.to_string()) } #[tauri::command] pub fn get_workspace_variables( db: State, workspace_id: String, ) -> Result, String> { let service = VariableService::new(db.inner().clone()); service.get_by_workspace(&workspace_id).map_err(|e| e.to_string()) } #[tauri::command] pub fn get_collection_variables( db: State, collection_id: String, ) -> Result, String> { let service = VariableService::new(db.inner().clone()); service.get_by_collection(&collection_id).map_err(|e| e.to_string()) } #[tauri::command] pub fn get_request_variables( db: State, request_id: String, ) -> Result, String> { let service = VariableService::new(db.inner().clone()); service.get_by_request(&request_id).map_err(|e| e.to_string()) } #[tauri::command] pub fn get_resolved_variables( db: State, workspace_id: Option, collection_id: Option, request_id: Option, ) -> Result, String> { let service = VariableService::new(db.inner().clone()); service .get_resolved( workspace_id.as_deref(), collection_id.as_deref(), request_id.as_deref(), ) .map_err(|e| e.to_string()) } #[tauri::command] pub fn create_variable( db: State, input: CreateVariableInput, ) -> Result { let service = VariableService::new(db.inner().clone()); service.create(input).map_err(|e| e.to_string()) } #[tauri::command] pub fn update_variable( db: State, input: UpdateVariableInput, ) -> Result { let service = VariableService::new(db.inner().clone()); service.update(input).map_err(|e| e.to_string()) } #[tauri::command] pub fn delete_variable(db: State, id: String) -> Result<(), String> { let service = VariableService::new(db.inner().clone()); service.delete(&id).map_err(|e| e.to_string()) }