headless_lms_server/controllers/course_material/
oembed.rs

1use crate::prelude::*;
2
3use headless_lms_utils::url_to_oembed_endpoint::{
4    OEmbedRequest, OEmbedResponse, mentimeter_oembed_response_builder,
5};
6
7/**
8GET `/api/v0/course-material/oembed/mentimeter?url=https://menti.com/123qwerty`
9*/
10async fn get_mentimeter_oembed_data(
11    query_params: web::Query<OEmbedRequest>,
12    app_conf: web::Data<ApplicationConfiguration>,
13    user: AuthUser,
14    pool: web::Data<PgPool>,
15) -> ControllerResult<web::Json<OEmbedResponse>> {
16    let mut conn = pool.acquire().await?;
17    let url = query_params.url.to_string();
18    let response = mentimeter_oembed_response_builder(url, app_conf.base_url.to_string())?;
19    let token = authorize(&mut conn, Act::View, Some(user.id), Res::AnyCourse).await?;
20    token.authorized_ok(web::Json(response))
21}
22
23/**
24Add a route for each controller in this module.
25
26The name starts with an underline in order to appear before other functions in the module documentation.
27
28We add the routes by calling the route method instead of using the route annotations because this method preserves the function signatures for documentation.
29*/
30pub fn _add_routes(cfg: &mut ServiceConfig) {
31    cfg.route("/mentimeter", web::get().to(get_mentimeter_oembed_data));
32}