headless_lms_server/controllers/main_frontend/
email_templates.rs

1//! Controllers for requests starting with `/api/v0/main-frontend/email-templates/`.
2
3use models::email_templates::EmailTemplate;
4
5use crate::prelude::*;
6
7/**
8DELETE `/api/v0/main-frontend/email-templates/:id`
9*/
10#[instrument(skip(pool))]
11async fn delete_email_template(
12    email_template_id: web::Path<Uuid>,
13    pool: web::Data<PgPool>,
14    user: AuthUser,
15) -> ControllerResult<web::Json<EmailTemplate>> {
16    let mut conn = pool.acquire().await?;
17    let deleted =
18        models::email_templates::delete_email_template(&mut conn, *email_template_id).await?;
19
20    let token = authorize(&mut conn, Act::Teach, Some(user.id), Res::AnyCourse).await?;
21    token.authorized_ok(web::Json(deleted))
22}
23
24/**
25Add a route for each controller in this module.
26
27The name starts with an underline in order to appear before other functions in the module documentation.
28
29We add the routes by calling the route method instead of using the route annotations because this method preserves the function signatures for documentation.
30*/
31pub fn _add_routes(cfg: &mut ServiceConfig) {
32    cfg.route(
33        "/{email_template_id}",
34        web::delete().to(delete_email_template),
35    );
36}