headless_lms_server/controllers/main_frontend/
org.rs

1//! Controllers for requests starting with `/api/v0/main-frontend/org`.
2
3use models::organizations::Organization;
4
5use crate::{domain::authorization::skip_authorize, prelude::*};
6
7/**
8GET `/api/v0/main-frontend/org/:slug
9*/
10
11#[instrument(skip(pool, file_store, app_conf))]
12async fn get_organization_by_slug(
13    pool: web::Data<PgPool>,
14    organization_slug: web::Path<String>,
15    file_store: web::Data<dyn FileStore>,
16    app_conf: web::Data<ApplicationConfiguration>,
17) -> ControllerResult<web::Json<Organization>> {
18    let mut conn = pool.acquire().await?;
19    let db_organization =
20        models::organizations::get_organization_by_slug(&mut conn, &organization_slug).await?;
21    let organization =
22        Organization::from_database_organization(db_organization, file_store.as_ref(), &app_conf);
23
24    let token = skip_authorize();
25    token.authorized_ok(web::Json(organization))
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(
37        "/{organization_slug}",
38        web::get().to(get_organization_by_slug),
39    );
40}