headless_lms_server/controllers/main_frontend/
glossary.rs

1use models::glossary::{self, TermUpdate};
2
3use crate::prelude::*;
4
5#[instrument(skip(pool))]
6async fn update(
7    id: web::Path<Uuid>,
8    update: web::Json<TermUpdate>,
9    pool: web::Data<PgPool>,
10    user: AuthUser,
11) -> ControllerResult<HttpResponse> {
12    let mut conn = pool.acquire().await?;
13    glossary::update(&mut conn, *id, &update.term, &update.definition).await?;
14
15    let token = authorize(&mut conn, Act::Teach, Some(user.id), Res::AnyCourse).await?;
16    token.authorized_ok(HttpResponse::Ok().finish())
17}
18
19#[instrument(skip(pool))]
20async fn delete(
21    id: web::Path<Uuid>,
22    pool: web::Data<PgPool>,
23    user: AuthUser,
24) -> ControllerResult<HttpResponse> {
25    let mut conn = pool.acquire().await?;
26    glossary::delete(&mut conn, *id).await?;
27
28    let token = authorize(&mut conn, Act::Teach, Some(user.id), Res::AnyCourse).await?;
29    token.authorized_ok(HttpResponse::Ok().finish())
30}
31
32/**
33Add a route for each controller in this module.
34
35The name starts with an underline in order to appear before other functions in the module documentation.
36
37We add the routes by calling the route method instead of using the route annotations because this method preserves the function signatures for documentation.
38*/
39pub fn _add_routes(cfg: &mut ServiceConfig) {
40    cfg.route("/{term_id}", web::put().to(update))
41        .route("/{term_id}", web::delete().to(delete));
42}