headless_lms_server/controllers/main_frontend/
feedback.rs

1use models::feedback;
2
3use crate::prelude::*;
4
5#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
6#[cfg_attr(feature = "ts_rs", derive(TS))]
7pub struct MarkAsRead {
8    read: bool,
9}
10
11/**
12POST `/api/v0/main-frontend/feedback/:id` - Creates new feedback.
13*/
14#[instrument(skip(pool))]
15pub async fn mark_as_read(
16    feedback_id: web::Path<Uuid>,
17    mark_as_read: web::Json<MarkAsRead>,
18    pool: web::Data<PgPool>,
19    user: AuthUser,
20) -> ControllerResult<HttpResponse> {
21    let mut conn = pool.acquire().await?;
22    feedback::mark_as_read(&mut conn, *feedback_id, mark_as_read.into_inner().read).await?;
23
24    let token = authorize(&mut conn, Act::Teach, Some(user.id), Res::AnyCourse).await?;
25    token.authorized_ok(HttpResponse::Ok().finish())
26}
27
28/**
29Add a route for each controller in this module.
30
31The name starts with an underline in order to appear before other functions in the module documentation.
32
33We add the routes by calling the route method instead of using the route annotations because this method preserves the function signatures for documentation.
34*/
35pub fn _add_routes(cfg: &mut ServiceConfig) {
36    cfg.route("/{feedback_id}", web::post().to(mark_as_read));
37}