api/routes/modules/assignments/tasks/mod.rs
1//! Task Routes Module
2//!
3//! This module defines the routing for assignment task-related endpoints, including retrieving, editing, creating, and deleting task details. It applies access control middleware to ensure only lecturers or admins can access these endpoints.
4
5use axum::{Router, routing::{get, post, put, delete}};
6use get::{get_task_details, list_tasks};
7use put::edit_task;
8use post::create_task;
9use delete::delete_task;
10use util::state::AppState;
11
12pub mod get;
13pub mod put;
14pub mod post;
15pub mod delete;
16pub mod common;
17
18/// Registers the routes for assignment task endpoints.
19///
20/// This function sets up the following endpoints under the current router:
21///
22/// - `GET /`: Lists all tasks for the assignment. Access is restricted to users with lecturer or admin roles for the assignment.
23/// - `POST /`: Creates a new task for the assignment. Access is restricted to users with lecturer or admin roles for the assignment.
24/// - `GET /{task_id}`: Retrieves detailed information about a specific task. Access is restricted to users with lecturer or admin roles for the assignment.
25/// - `PUT /{task_id}`: Edits the command of a specific task. Access is restricted to users with lecturer or admin roles for the assignment.
26/// - `DELETE /{task_id}`: Deletes a specific task from the assignment. Access is restricted to users with lecturer or admin roles for the assignment.
27///
28/// All routes apply the `require_lecturer_or_admin` middleware, which checks the user's role for the assignment before allowing access.
29///
30/// # Returns
31/// An [`axum::Router`] with the task endpoints and their associated middleware.
32pub fn tasks_routes() -> Router<AppState> {
33 Router::new()
34 .route("/", get(list_tasks))
35 .route("/", post(create_task))
36 .route("/{task_id}", get(get_task_details))
37 .route("/{task_id}", put(edit_task))
38 .route("/{task_id}", delete(delete_task))
39}