Split the Dashboard from All Tasks. (#10)
Reviewed-on: #10 Co-authored-by: Drew Galbraith <drew@tiramisu.one> Co-committed-by: Drew Galbraith <drew@tiramisu.one>
This commit is contained in:
parent
b0916990fb
commit
8e6ac03f70
10 changed files with 572 additions and 23 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use axum::{
|
||||
Json, Router,
|
||||
extract::{Path, State},
|
||||
extract::{Path, Query, State},
|
||||
http::StatusCode,
|
||||
routing::{get, post},
|
||||
};
|
||||
|
|
@ -40,10 +40,19 @@ pub async fn create_task(
|
|||
Ok((StatusCode::CREATED, Json(model)))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Filters {
|
||||
status: Option<TaskStatus>,
|
||||
}
|
||||
|
||||
pub async fn list_tasks(
|
||||
State(pool): State<Pool<Sqlite>>,
|
||||
Query(filters): Query<Filters>,
|
||||
) -> Result<(StatusCode, Json<Vec<TaskModel>>), AppError> {
|
||||
let tasks = TaskModel::list_all(&pool).await?;
|
||||
let tasks = match filters.status {
|
||||
Some(status) => TaskModel::list_by_status(&pool, status).await?,
|
||||
None => TaskModel::list_all(&pool).await?,
|
||||
};
|
||||
|
||||
Ok((StatusCode::OK, Json(tasks)))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue