headless_lms_server/controllers/main_frontend/
feedback.rs

1use models::feedback;
2use utoipa::{OpenApi, ToSchema};
3
4use crate::prelude::*;
5
6#[derive(OpenApi)]
7#[openapi(paths(mark_as_read))]
8pub(crate) struct MainFrontendFeedbackApiDoc;
9
10#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, ToSchema)]
11
12pub struct MarkAsRead {
13    read: bool,
14}
15
16/**
17POST `/api/v0/main-frontend/feedback/:id` - Creates new feedback.
18*/
19#[utoipa::path(
20    post,
21    path = "/{feedback_id}",
22    operation_id = "markFeedbackAsRead",
23    tag = "feedback",
24    params(
25        ("feedback_id" = String, Path, description = "Feedback id")
26    ),
27    request_body = MarkAsRead,
28    responses(
29        (status = 200, description = "Feedback read state updated")
30    )
31)]
32#[instrument(skip(pool))]
33pub async fn mark_as_read(
34    feedback_id: web::Path<Uuid>,
35    mark_as_read: web::Json<MarkAsRead>,
36    pool: web::Data<PgPool>,
37    user: AuthUser,
38) -> ControllerResult<HttpResponse> {
39    let mut conn = pool.acquire().await?;
40    feedback::mark_as_read(&mut conn, *feedback_id, mark_as_read.into_inner().read).await?;
41
42    let token = authorize(&mut conn, Act::Teach, Some(user.id), Res::AnyCourse).await?;
43    token.authorized_ok(HttpResponse::Ok().finish())
44}
45
46/**
47Add a route for each controller in this module.
48
49The name starts with an underline in order to appear before other functions in the module documentation.
50
51We add the routes by calling the route method instead of using the route annotations because this method preserves the function signatures for documentation.
52*/
53pub fn _add_routes(cfg: &mut ServiceConfig) {
54    cfg.route("/{feedback_id}", web::post().to(mark_as_read));
55}