diff --git a/backend/src/services/tasks.rs b/backend/src/services/tasks.rs index bad5eab..3773f01 100644 --- a/backend/src/services/tasks.rs +++ b/backend/src/services/tasks.rs @@ -15,10 +15,12 @@ use crate::models::{TaskModel, TaskStatus}; use super::AppError; pub fn create_task_router() -> Router> { - Router::new().route("/", post(create_task)).route( - "/{task_id}", - get(get_task).put(update_task).delete(delete_task), - ) + Router::new() + .route("/", post(create_task).get(list_tasks)) + .route( + "/{task_id}", + get(get_task).put(update_task).delete(delete_task), + ) } #[derive(Deserialize)] @@ -38,6 +40,14 @@ pub async fn create_task( Ok((StatusCode::CREATED, Json(model))) } +pub async fn list_tasks( + State(pool): State>, +) -> Result<(StatusCode, Json>), AppError> { + let tasks = TaskModel::list_all(&pool).await?; + + Ok((StatusCode::OK, Json(tasks))) +} + pub async fn get_task( State(pool): State>, WithRejection(Path(task_id), _): WithRejection, AppError>, diff --git a/backend/tests/api/list_tasks.hurl b/backend/tests/api/list_tasks.hurl index 9d9f7be..f1f1449 100644 --- a/backend/tests/api/list_tasks.hurl +++ b/backend/tests/api/list_tasks.hurl @@ -5,7 +5,7 @@ GET {{host}}/api/tasks HTTP 200 [Captures] -initial_count: jsonpath "$ length" +initial_count: jsonpath "$" count [Asserts] jsonpath "$" isCollection @@ -51,7 +51,7 @@ GET {{host}}/api/tasks HTTP 200 [Asserts] jsonpath "$" isCollection -jsonpath "$ length" >= {{initial_count}} +jsonpath "$" count >= {{initial_count}} jsonpath "$[*].id" includes "{{alpha_task_id}}" jsonpath "$[*].id" includes "{{beta_task_id}}" jsonpath "$[*].id" includes "{{gamma_task_id}}" @@ -140,4 +140,4 @@ GET {{host}}/api/tasks HTTP 200 [Asserts] jsonpath "$[*].id" not includes "{{beta_task_id}}" -jsonpath "$[*].id" not includes "{{gamma_task_id}}" \ No newline at end of file +jsonpath "$[*].id" not includes "{{gamma_task_id}}"