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;
4
5use crate::prelude::*;
6
7/**
8GET /organizations/:organization_id - Get organization.
9*/
10#[instrument(skip(pool, file_store, app_conf))]
11async fn get_organization(
12    organization_id: web::Path<Uuid>,
13    pool: web::Data<PgPool>,
14    file_store: web::Data<dyn FileStore>,
15    app_conf: web::Data<ApplicationConfiguration>,
16) -> ControllerResult<web::Json<Organization>> {
17    let mut conn = pool.acquire().await?;
18    let token = skip_authorize();
19    let db_organization =
20        models::organizations::get_organization(&mut conn, *organization_id).await?;
21    let organization =
22        Organization::from_database_organization(db_organization, file_store.as_ref(), &app_conf);
23    token.authorized_ok(web::Json(organization))
24}
25
26/**
27Add a route for each controller in this module.
28
29The name starts with an underline in order to appear before other functions in the module documentation.
30
31We add the routes by calling the route method instead of using the route annotations because this method preserves the function signatures for documentation.
32*/
33pub fn _add_routes(cfg: &mut ServiceConfig) {
34    cfg.route("/{organization_id}", web::get().to(get_organization));
35}