mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-22 17:39:46 +01:00
Environment deletion and better actions menu
This commit is contained in:
@@ -479,6 +479,19 @@ async fn delete_request(
|
||||
emit_and_return(&window, "deleted_model", req)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn delete_environment(
|
||||
window: Window<Wry>,
|
||||
db_instance: State<'_, Mutex<Pool<Sqlite>>>,
|
||||
environment_id: &str,
|
||||
) -> Result<models::Environment, String> {
|
||||
let pool = &*db_instance.lock().await;
|
||||
let req = models::delete_environment(environment_id, pool)
|
||||
.await
|
||||
.expect("Failed to delete environment");
|
||||
emit_and_return(&window, "deleted_model", req)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn list_requests(
|
||||
workspace_id: &str,
|
||||
@@ -600,10 +613,10 @@ async fn new_window(window: Window<Wry>, url: &str) -> Result<(), String> {
|
||||
async fn delete_workspace(
|
||||
window: Window<Wry>,
|
||||
db_instance: State<'_, Mutex<Pool<Sqlite>>>,
|
||||
id: &str,
|
||||
workspace_id: &str,
|
||||
) -> Result<models::Workspace, String> {
|
||||
let pool = &*db_instance.lock().await;
|
||||
let workspace = models::delete_workspace(id, pool)
|
||||
let workspace = models::delete_workspace(workspace_id, pool)
|
||||
.await
|
||||
.expect("Failed to delete workspace");
|
||||
emit_and_return(&window, "deleted_model", workspace)
|
||||
@@ -643,6 +656,7 @@ fn main() {
|
||||
create_request,
|
||||
create_workspace,
|
||||
delete_all_responses,
|
||||
delete_environment,
|
||||
delete_request,
|
||||
delete_response,
|
||||
delete_workspace,
|
||||
|
||||
@@ -252,13 +252,27 @@ pub async fn create_environment(
|
||||
get_environment(&id, pool).await
|
||||
}
|
||||
|
||||
pub async fn delete_environment(id: &str, pool: &Pool<Sqlite>) -> Result<Environment, sqlx::Error> {
|
||||
let env = get_environment(id, pool).await?;
|
||||
let _ = sqlx::query!(
|
||||
r#"
|
||||
DELETE FROM environments
|
||||
WHERE id = ?
|
||||
"#,
|
||||
id,
|
||||
)
|
||||
.execute(pool)
|
||||
.await;
|
||||
|
||||
Ok(env)
|
||||
}
|
||||
|
||||
pub async fn update_environment(
|
||||
id: &str,
|
||||
name: &str,
|
||||
data: HashMap<String, JsonValue>,
|
||||
pool: &Pool<Sqlite>,
|
||||
) -> Result<Environment, sqlx::Error> {
|
||||
println!("DATA: {}", data.clone().len());
|
||||
let json_data = Json(data);
|
||||
sqlx::query!(
|
||||
r#"
|
||||
@@ -457,6 +471,10 @@ pub async fn get_request(id: &str, pool: &Pool<Sqlite>) -> Result<HttpRequest, s
|
||||
|
||||
pub async fn delete_request(id: &str, pool: &Pool<Sqlite>) -> Result<HttpRequest, sqlx::Error> {
|
||||
let req = get_request(id, pool).await?;
|
||||
|
||||
// DB deletes will cascade but this will delete the files
|
||||
delete_all_responses(id, pool).await?;
|
||||
|
||||
let _ = sqlx::query!(
|
||||
r#"
|
||||
DELETE FROM http_requests
|
||||
@@ -467,8 +485,6 @@ pub async fn delete_request(id: &str, pool: &Pool<Sqlite>) -> Result<HttpRequest
|
||||
.execute(pool)
|
||||
.await;
|
||||
|
||||
delete_all_responses(id, pool).await?;
|
||||
|
||||
Ok(req)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user