headless_lms_server/controllers/course_material/
organizations.rs

1//! Controllers for requests starting with `/api/v0/course-material/organizations`.
2
3use headless_lms_models::organizations::Organization;
4use utoipa::OpenApi;
5
6use crate::prelude::*;
7
8#[derive(OpenApi)]
9#[openapi(paths(get_organization))]
10pub(crate) struct CourseMaterialOrganizationsApiDoc;
11
12/**
13GET /organizations/:organization_id - Get organization.
14*/
15#[utoipa::path(
16    get,
17    path = "/{organization_id}",
18    operation_id = "getCourseMaterialOrganization",
19    tag = "course-material-organizations",
20    params(
21        ("organization_id" = Uuid, Path, description = "Organization id")
22    ),
23    responses(
24        (status = 200, description = "Organization", body = Organization)
25    )
26)]
27#[instrument(skip(pool, file_store, app_conf))]
28async fn get_organization(
29    organization_id: web::Path<Uuid>,
30    pool: web::Data<PgPool>,
31    file_store: web::Data<dyn FileStore>,
32    app_conf: web::Data<ApplicationConfiguration>,
33) -> ControllerResult<web::Json<Organization>> {
34    let mut conn = pool.acquire().await?;
35    let token = skip_authorize();
36    let db_organization =
37        models::organizations::get_organization(&mut conn, *organization_id).await?;
38    let organization =
39        Organization::from_database_organization(db_organization, file_store.as_ref(), &app_conf);
40    token.authorized_ok(web::Json(organization))
41}
42
43/**
44Add a route for each controller in this module.
45
46The name starts with an underline in order to appear before other functions in the module documentation.
47
48We add the routes by calling the route method instead of using the route annotations because this method preserves the function signatures for documentation.
49*/
50pub fn _add_routes(cfg: &mut ServiceConfig) {
51    cfg.route("/{organization_id}", web::get().to(get_organization));
52}