headless_lms_server/controllers/cms/
course_instances.rs

1//! Controllers for requests starting with `/api/v0/cms/course-instances`.
2
3use crate::prelude::*;
4
5/**
6GET `/api/v8/course-instances/:course_instance` - Gets a course instance by id.
7
8# Example
9Request: `GET /api/v8/course-instances/e051ddb5-2128-4215-adda-ebd74a0ea46b`
10*/
11#[instrument(skip(pool))]
12async fn get_organization_id(
13    course_instance_id: web::Path<Uuid>,
14    pool: web::Data<PgPool>,
15    user: AuthUser,
16) -> ControllerResult<web::Json<Uuid>> {
17    let mut conn = pool.acquire().await?;
18    let token = authorize(
19        &mut conn,
20        Act::View,
21        Some(user.id),
22        Res::CourseInstance(*course_instance_id),
23    )
24    .await?;
25    let organization =
26        models::course_instances::get_organization_id(&mut conn, *course_instance_id).await?;
27    token.authorized_ok(web::Json(organization))
28}
29
30/**
31Add a route for each controller in this module.
32
33The name starts with an underline in order to appear before other functions in the module documentation.
34
35We add the routes by calling the route method instead of using the route annotations because this method preserves the function signatures for documentation.
36*/
37pub fn _add_routes(cfg: &mut ServiceConfig) {
38    cfg.route(
39        "/{course_instance_id}/organization",
40        web::get().to(get_organization_id),
41    );
42}