headless_lms_server/controllers/cms/
repository_exercises.rs

1use crate::prelude::*;
2use models::repository_exercises::{self, RepositoryExercise};
3
4#[instrument(skip(pool))]
5pub async fn get_for_course(
6    course_id: web::Path<Uuid>,
7    pool: web::Data<PgPool>,
8    user: Option<AuthUser>,
9) -> ControllerResult<web::Json<Vec<RepositoryExercise>>> {
10    let mut conn = pool.acquire().await?;
11    let token = authorize(
12        &mut conn,
13        Act::Teach,
14        user.map(|u| u.id),
15        Res::Course(*course_id),
16    )
17    .await?;
18
19    let exercises = repository_exercises::get_for_course(&mut conn, *course_id).await?;
20    token.authorized_ok(web::Json(exercises))
21}
22
23/**
24Add a route for each controller in this module.
25
26The name starts with an underline in order to appear before other functions in the module documentation.
27
28We add the routes by calling the route method instead of using the route annotations because this method preserves the function signatures for documentation.
29*/
30pub fn _add_routes(cfg: &mut ServiceConfig) {
31    cfg.route("/{course_id}", web::get().to(get_for_course));
32}