headless_lms_server/controllers/course_material/
glossary.rs

1use models::glossary::TermUpdate;
2
3use crate::prelude::*;
4
5#[instrument(skip(pool))]
6async fn update(
7    pool: web::Data<PgPool>,
8    acronym_id: web::Path<Uuid>,
9    update: web::Json<TermUpdate>,
10    user: AuthUser,
11) -> ControllerResult<HttpResponse> {
12    let mut conn = pool.acquire().await?;
13    models::glossary::update(&mut conn, *acronym_id, &update.term, &update.definition).await?;
14    let token = authorize(&mut conn, Act::View, Some(user.id), Res::AnyCourse).await?;
15    token.authorized_ok(HttpResponse::Ok().finish())
16}
17
18#[instrument(skip(pool))]
19async fn delete(
20    pool: web::Data<PgPool>,
21    acronym_id: web::Path<Uuid>,
22    user: AuthUser,
23) -> ControllerResult<HttpResponse> {
24    let mut conn = pool.acquire().await?;
25    models::glossary::delete(&mut conn, *acronym_id).await?;
26    let token = authorize(&mut conn, Act::View, Some(user.id), Res::AnyCourse).await?;
27    token.authorized_ok(HttpResponse::Ok().finish())
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("/{id}/update", web::put().to(update))
39        .route("/{id}/delete", web::delete().to(delete));
40}