api/routes/modules/assignments/interpreter/
mod.rs

1//! File Routes Module
2//!
3//! This module defines the routing for assignment file-related endpoints, including uploading, listing, downloading, and deleting files. It applies access control middleware to ensure appropriate permissions for each operation.
4
5use crate::{auth::guards::{require_lecturer}, routes::modules::assignments::interpreter::get::get_interpreter_info};
6use axum::{
7    Router,
8    middleware::from_fn_with_state,
9    routing::{delete, get, post},
10};
11use delete::delete_interpreter;
12use get::download_interpreter;
13use post::upload_interpreter;
14use util::state::AppState;
15
16pub mod delete;
17pub mod get;
18pub mod post;
19
20/// Registers the routes for assignment file endpoints.
21///
22/// This function sets up the following endpoints under the current router:
23///
24/// - `POST /`: Upload files to an assignment. Access is restricted to lecturers assigned to the module.
25/// - `GET /`: List all files for an assignment. Access is restricted to lecturers assigned to the module.
26/// - `GET /{file_id}`: Download a specific file from an assignment. Access is restricted to lecturers assigned to the module.
27/// - `DELETE /`: Delete files from an assignment. Access is restricted to lecturers assigned to the module.
28///
29/// Routes apply appropriate middleware based on the operation:
30/// - Upload and delete operations require lecturer permissions
31/// - List and download operations require module assignment
32///
33/// # Returns
34/// An [`axum::Router`] with the file endpoints and their associated middleware.
35pub fn interpreter_routes(app_state: AppState) -> Router<AppState> {
36    Router::new()
37        .route("/",post(upload_interpreter).route_layer(from_fn_with_state(app_state.clone(), require_lecturer)))
38        .route("/",get(download_interpreter).route_layer(from_fn_with_state(app_state.clone(),require_lecturer)))
39        .route("/info",get(get_interpreter_info).route_layer(from_fn_with_state(app_state.clone(), require_lecturer)))
40        .route("/",delete(delete_interpreter).route_layer(from_fn_with_state(app_state.clone(), require_lecturer)))
41}