headless_lms_server/controllers/
mod.rs

1/*!
2Handlers for HTTP requests to `/api/v0`.
3
4This documents all endpoints. Select a module below for a namespace.
5
6*/
7
8// tracing::instrument seems to have issues with this
9#![allow(clippy::suspicious_else_formatting)]
10
11pub mod auth;
12pub mod cms;
13pub mod course_material;
14pub mod exercise_services;
15pub mod files;
16pub mod health;
17pub mod helpers;
18pub mod langs;
19pub mod main_frontend;
20pub mod mock_azure;
21pub mod other_domain_redirects;
22pub mod study_registry;
23pub mod tmc_server;
24
25use crate::domain::error::{ControllerError, ControllerErrorType};
26use actix_web::{
27    HttpRequest, HttpResponse, ResponseError,
28    web::{self, ServiceConfig},
29};
30use headless_lms_utils::prelude::*;
31use serde::{Deserialize, Serialize};
32use utoipa::ToSchema;
33
34/// Result of a image upload. Tells where the uploaded image can be retrieved from.
35#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, ToSchema)]
36
37pub struct UploadResult {
38    pub url: String,
39}
40
41/// Add controllers from all the submodules.
42pub fn configure_controllers(
43    cfg: &mut ServiceConfig,
44    app_conf: web::Data<ApplicationConfiguration>,
45) {
46    cfg.service(web::scope("/course-material").configure(course_material::_add_routes))
47        .service(web::scope("/cms").configure(cms::_add_routes))
48        .service(web::scope("/files").configure(files::_add_routes))
49        .service(web::scope("/main-frontend").configure(main_frontend::_add_routes))
50        .service(web::scope("/auth").configure(auth::_add_routes))
51        .service(web::scope("/study-registry").configure(study_registry::_add_routes))
52        .service(web::scope("/exercise-services").configure(exercise_services::_add_routes))
53        .service(
54            web::scope("/other-domain-redirects").configure(other_domain_redirects::_add_routes),
55        )
56        .service(web::scope("/health").configure(health::_add_routes))
57        .service(web::scope("/langs").configure(langs::_add_routes))
58        .service(web::scope("/tmc-server").configure(tmc_server::_add_routes))
59        .default_service(web::to(not_found));
60    if app_conf.test_chatbot && app_conf.test_mode {
61        cfg.service(web::scope("/mock-azure").configure(mock_azure::_add_routes));
62    }
63}
64
65async fn not_found(req: HttpRequest) -> HttpResponse {
66    ControllerError::new(
67        ControllerErrorType::NotFound,
68        format!("No handler found for route '{}'", req.path()),
69        None,
70    )
71    .error_response()
72}