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 healthz;
17pub mod helpers;
18pub mod langs;
19pub mod main_frontend;
20pub mod other_domain_redirects;
21pub mod study_registry;
22pub mod tmc_server;
23
24use crate::domain::error::{ControllerError, ControllerErrorType};
25use actix_web::{
26    HttpRequest, HttpResponse, ResponseError,
27    web::{self, ServiceConfig},
28};
29use headless_lms_utils::prelude::*;
30use serde::{Deserialize, Serialize};
31#[cfg(feature = "ts_rs")]
32use ts_rs::TS;
33
34/// Result of a image upload. Tells where the uploaded image can be retrieved from.
35#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
36#[cfg_attr(feature = "ts_rs", derive(TS))]
37pub struct UploadResult {
38    pub url: String,
39}
40
41/// Add controllers from all the submodules.
42pub fn configure_controllers(cfg: &mut ServiceConfig) {
43    cfg.service(web::scope("/course-material").configure(course_material::_add_routes))
44        .service(web::scope("/cms").configure(cms::_add_routes))
45        .service(web::scope("/files").configure(files::_add_routes))
46        .service(web::scope("/main-frontend").configure(main_frontend::_add_routes))
47        .service(web::scope("/auth").configure(auth::_add_routes))
48        .service(web::scope("/study-registry").configure(study_registry::_add_routes))
49        .service(web::scope("/exercise-services").configure(exercise_services::_add_routes))
50        .service(
51            web::scope("/other-domain-redirects").configure(other_domain_redirects::_add_routes),
52        )
53        .service(web::scope("/healthz").configure(healthz::_add_routes))
54        .service(web::scope("/langs").configure(langs::_add_routes))
55        .service(web::scope("/tmc-server").configure(tmc_server::_add_routes))
56        .default_service(web::to(not_found));
57}
58
59async fn not_found(req: HttpRequest) -> HttpResponse {
60    ControllerError::new(
61        ControllerErrorType::NotFound,
62        format!("No handler found for route '{}'", req.path()),
63        None,
64    )
65    .error_response()
66}