Create the remaining task api methods on the server. #3
2 changed files with 17 additions and 7 deletions
|
|
@ -15,7 +15,9 @@ use crate::models::{TaskModel, TaskStatus};
|
||||||
use super::AppError;
|
use super::AppError;
|
||||||
|
|
||||||
pub fn create_task_router() -> Router<Pool<Sqlite>> {
|
pub fn create_task_router() -> Router<Pool<Sqlite>> {
|
||||||
Router::new().route("/", post(create_task)).route(
|
Router::new()
|
||||||
|
.route("/", post(create_task).get(list_tasks))
|
||||||
|
.route(
|
||||||
"/{task_id}",
|
"/{task_id}",
|
||||||
get(get_task).put(update_task).delete(delete_task),
|
get(get_task).put(update_task).delete(delete_task),
|
||||||
)
|
)
|
||||||
|
|
@ -38,6 +40,14 @@ pub async fn create_task(
|
||||||
Ok((StatusCode::CREATED, Json(model)))
|
Ok((StatusCode::CREATED, Json(model)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn list_tasks(
|
||||||
|
State(pool): State<Pool<Sqlite>>,
|
||||||
|
) -> Result<(StatusCode, Json<Vec<TaskModel>>), AppError> {
|
||||||
|
let tasks = TaskModel::list_all(&pool).await?;
|
||||||
|
|
||||||
|
Ok((StatusCode::OK, Json(tasks)))
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn get_task(
|
pub async fn get_task(
|
||||||
State(pool): State<Pool<Sqlite>>,
|
State(pool): State<Pool<Sqlite>>,
|
||||||
WithRejection(Path(task_id), _): WithRejection<Path<Uuid>, AppError>,
|
WithRejection(Path(task_id), _): WithRejection<Path<Uuid>, AppError>,
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ GET {{host}}/api/tasks
|
||||||
|
|
||||||
HTTP 200
|
HTTP 200
|
||||||
[Captures]
|
[Captures]
|
||||||
initial_count: jsonpath "$ length"
|
initial_count: jsonpath "$" count
|
||||||
[Asserts]
|
[Asserts]
|
||||||
jsonpath "$" isCollection
|
jsonpath "$" isCollection
|
||||||
|
|
||||||
|
|
@ -51,7 +51,7 @@ GET {{host}}/api/tasks
|
||||||
HTTP 200
|
HTTP 200
|
||||||
[Asserts]
|
[Asserts]
|
||||||
jsonpath "$" isCollection
|
jsonpath "$" isCollection
|
||||||
jsonpath "$ length" >= {{initial_count}}
|
jsonpath "$" count >= {{initial_count}}
|
||||||
jsonpath "$[*].id" includes "{{alpha_task_id}}"
|
jsonpath "$[*].id" includes "{{alpha_task_id}}"
|
||||||
jsonpath "$[*].id" includes "{{beta_task_id}}"
|
jsonpath "$[*].id" includes "{{beta_task_id}}"
|
||||||
jsonpath "$[*].id" includes "{{gamma_task_id}}"
|
jsonpath "$[*].id" includes "{{gamma_task_id}}"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue