Add delete endpoint.
This commit is contained in:
parent
0745e8381c
commit
229512ec0b
1 changed files with 15 additions and 3 deletions
|
|
@ -15,9 +15,10 @@ use crate::models::{TaskModel, TaskStatus};
|
|||
use super::AppError;
|
||||
|
||||
pub fn create_task_router() -> Router<Pool<Sqlite>> {
|
||||
Router::new()
|
||||
.route("/", post(create_task))
|
||||
.route("/{task_id}", get(get_task).put(update_task))
|
||||
Router::new().route("/", post(create_task)).route(
|
||||
"/{task_id}",
|
||||
get(get_task).put(update_task).delete(delete_task),
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
|
@ -82,3 +83,14 @@ pub async fn update_task(
|
|||
|
||||
Ok((StatusCode::OK, Json(model)))
|
||||
}
|
||||
|
||||
pub async fn delete_task(
|
||||
State(pool): State<Pool<Sqlite>>,
|
||||
WithRejection(Path(task_id), _): WithRejection<Path<Uuid>, AppError>,
|
||||
) -> Result<StatusCode, AppError> {
|
||||
// Ensure that the task exists.
|
||||
TaskModel::get_by_id(&pool, task_id).await?;
|
||||
TaskModel::delete(&pool, task_id).await?;
|
||||
|
||||
Ok(StatusCode::NO_CONTENT)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue