headless_lms_server/controllers/main_frontend/
org.rs1use models::organizations::Organization;
4use utoipa::OpenApi;
5
6use crate::{domain::authorization::skip_authorize, prelude::*};
7
8#[derive(OpenApi)]
9#[openapi(paths(get_organization_by_slug))]
10pub(crate) struct MainFrontendOrgApiDoc;
11
12#[utoipa::path(
16 get,
17 path = "/{organization_slug}",
18 operation_id = "getOrganizationBySlug",
19 tag = "org",
20 params(
21 ("organization_slug" = String, Path, description = "Organization slug")
22 ),
23 responses(
24 (status = 200, description = "Organization", body = Organization)
25 )
26)]
27#[instrument(skip(pool, file_store, app_conf))]
28async fn get_organization_by_slug(
29 pool: web::Data<PgPool>,
30 organization_slug: web::Path<String>,
31 file_store: web::Data<dyn FileStore>,
32 app_conf: web::Data<ApplicationConfiguration>,
33) -> ControllerResult<web::Json<Organization>> {
34 let mut conn = pool.acquire().await?;
35 let db_organization =
36 models::organizations::get_organization_by_slug(&mut conn, &organization_slug).await?;
37 let organization =
38 Organization::from_database_organization(db_organization, file_store.as_ref(), &app_conf);
39
40 let token = skip_authorize();
41 token.authorized_ok(web::Json(organization))
42}
43
44pub fn _add_routes(cfg: &mut ServiceConfig) {
52 cfg.route(
53 "/{organization_slug}",
54 web::get().to(get_organization_by_slug),
55 );
56}