feat: add delete schedule

This commit is contained in:
Ruben Fiszel
2022-07-20 17:37:04 +02:00
parent acb09d1ce1
commit f6d6934584
4 changed files with 66 additions and 4 deletions
+17
View File
@@ -2547,6 +2547,23 @@ paths:
schema:
type: string
/w/{workspace}/schedules/delete/{path}:
delete:
summary: delete schedule
operationId: deleteSchedule
tags:
- schedule
parameters:
- $ref: "#/components/parameters/WorkspaceId"
- $ref: "#/components/parameters/Path"
responses:
"200":
description: schedule deleted
content:
text/plain:
schema:
type: string
/w/{workspace}/schedules/get/{path}:
get:
summary: get schedule
+34 -1
View File
@@ -17,7 +17,7 @@ use crate::{
};
use axum::{
extract::{Extension, Path, Query},
routing::{get, post},
routing::{delete, get, post},
Json, Router,
};
@@ -33,6 +33,7 @@ pub fn workspaced_service() -> Router {
.route("/exists/*path", get(exists_schedule))
.route("/create", post(create_schedule))
.route("/update/*path", post(edit_schedule))
.route("/delete/*path", delete(delete_schedule))
.route("/setenabled/*path", post(set_enabled))
}
@@ -404,6 +405,38 @@ pub async fn set_enabled(
))
}
async fn delete_schedule(
authed: Authed,
Extension(user_db): Extension<UserDB>,
Path((w_id, path)): Path<(String, StripPath)>,
) -> Result<String> {
let path = path.to_path();
let mut tx = user_db.begin(&authed).await?;
sqlx::query!(
"DELETE FROM schedule WHERE path = $1 AND workspace_id = $2",
path,
w_id
)
.execute(&mut tx)
.await?;
audit_log(
&mut tx,
&authed.username,
"schedule.delete",
ActionKind::Delete,
&w_id,
Some(path),
None,
)
.await?;
tx.commit().await?;
Ok(format!("schedule {} deleted", path))
}
fn schedule_to_user(path: &str) -> String {
format!("schedule-{}", path.replace('/', "-"))
}
+1 -2
View File
@@ -325,7 +325,6 @@ async fn create_variable(
async fn delete_variable(
authed: Authed,
Extension(user_db): Extension<UserDB>,
Extension(db): Extension<DB>,
Path((w_id, path)): Path<(String, StripPath)>,
) -> Result<String> {
let path = path.to_path();
@@ -336,7 +335,7 @@ async fn delete_variable(
path,
w_id
)
.execute(&db)
.execute(&mut tx)
.await?;
audit_log(
&mut tx,
+14 -1
View File
@@ -13,7 +13,8 @@
faPlus,
faShare,
faToggleOff,
faToggleOn
faToggleOn,
faTrash
} from '@fortawesome/free-solid-svg-icons'
import { userStore, workspaceStore } from '$lib/stores'
import CenteredPage from '$lib/components/CenteredPage.svelte'
@@ -114,6 +115,18 @@
setScheduleEnabled(path, enabled ? false : true)
}
},
{
displayName: 'Delete',
icon: faTrash,
disabled: !canWrite,
action: async () => {
await ScheduleService.deleteSchedule({
workspace: $workspaceStore ?? '',
path
})
loadSchedules()
}
},
{
displayName: 'Edit',
icon: faEdit,