use tauri::State; use crate::connections::{ ConnectionGroup, ConnectionRecord, CreateConnectionInput, UpdateConnectionInput, }; use crate::AppState; /// Return all connections ordered by group then sort_order. #[tauri::command] pub fn list_connections(state: State<'_, AppState>) -> Result, String> { state.connections.list_connections() } /// Create a new connection and return the persisted record. #[tauri::command] pub fn create_connection( input: CreateConnectionInput, state: State<'_, AppState>, ) -> Result { state.connections.create_connection(input) } /// Fetch a single connection by id. #[tauri::command] pub fn get_connection(id: i64, state: State<'_, AppState>) -> Result { state.connections.get_connection(id) } /// Apply a partial update to a connection. /// /// Only fields present (i.e. `Some`) in `input` are written; all others are /// left unchanged. Returns `Err` if the connection id does not exist. #[tauri::command] pub fn update_connection( id: i64, input: UpdateConnectionInput, state: State<'_, AppState>, ) -> Result<(), String> { state.connections.update_connection(id, input) } /// Delete a connection by id. /// /// Returns `Err` if the id does not exist. #[tauri::command] pub fn delete_connection(id: i64, state: State<'_, AppState>) -> Result<(), String> { state.connections.delete_connection(id) } /// Return all connection groups ordered by parent then sort_order. #[tauri::command] pub fn list_groups(state: State<'_, AppState>) -> Result, String> { state.connections.list_groups() } /// Create a new connection group. /// /// `parent_id` is `None` for top-level groups. #[tauri::command] pub fn create_group( name: String, parent_id: Option, state: State<'_, AppState>, ) -> Result { state.connections.create_group(&name, parent_id) } /// Delete a connection group by id. /// /// Connections in the deleted group have their `group_id` set to NULL by the /// database's `ON DELETE SET NULL` constraint. #[tauri::command] pub fn delete_group(id: i64, state: State<'_, AppState>) -> Result<(), String> { state.connections.delete_group(id) } /// Rename a connection group. /// /// Returns `Err` if the id does not exist. #[tauri::command] pub fn rename_group(id: i64, name: String, state: State<'_, AppState>) -> Result<(), String> { state.connections.rename_group(id, &name) } /// Search connections across name, hostname, tags, and notes. /// /// Uses case-insensitive LIKE matching. Returns results ordered by name. #[tauri::command] pub fn search_connections( query: String, state: State<'_, AppState>, ) -> Result, String> { state.connections.search(&query) } #[tauri::command] pub fn reorder_connections( ids: Vec, state: State<'_, AppState>, ) -> Result<(), String> { state.connections.reorder_connections(&ids) } #[tauri::command] pub fn reorder_groups( ids: Vec, state: State<'_, AppState>, ) -> Result<(), String> { state.connections.reorder_groups(&ids) }