bios_iam/console_app/api/
iam_ca_res_api.rs1use tardis::web::context_extractor::TardisContextExtractor;
2use tardis::web::poem_openapi;
3use tardis::web::poem_openapi::{param::Path, param::Query};
4use tardis::web::web_resp::{TardisApiResult, TardisResp};
5
6use bios_basic::rbum::dto::rbum_rel_dto::RbumRelBoneResp;
7use bios_basic::rbum::dto::rbum_set_dto::RbumSetTreeResp;
8
9use crate::basic::serv::iam_res_serv::IamResServ;
10use crate::basic::serv::iam_set_serv::IamSetServ;
11use crate::iam_constants;
12use crate::iam_enumeration::{IamRelKind, IamSetKind};
13use bios_basic::helper::request_helper::try_set_real_ip_from_req_to_ctx;
14use tardis::web::poem::Request;
15#[derive(Clone, Default)]
16pub struct IamCaResApi;
17
18#[poem_openapi::OpenApi(prefix_path = "/ca/res", tag = "bios_basic::ApiTag::App")]
24impl IamCaResApi {
25 #[oai(path = "/tree", method = "get")]
28 async fn get_menu_tree(&self, exts: Query<Option<String>>, ctx: TardisContextExtractor, request: &Request) -> TardisApiResult<RbumSetTreeResp> {
29 try_set_real_ip_from_req_to_ctx(request, &ctx.0).await?;
30 let funs = iam_constants::get_tardis_inst();
31 let set_id = IamSetServ::get_set_id_by_code(&IamSetServ::get_default_code(&IamSetKind::Res, ""), true, &funs, &ctx.0).await?;
32 let result = IamSetServ::get_menu_tree(&set_id, exts.0, &funs, &ctx.0).await?;
33 ctx.0.execute_task().await?;
34 TardisResp::ok(result)
35 }
36
37 #[oai(path = "/:id/role", method = "get")]
40 async fn find_rel_roles(
41 &self,
42 id: Path<String>,
43 desc_by_create: Query<Option<bool>>,
44 desc_by_update: Query<Option<bool>>,
45 ctx: TardisContextExtractor,
46 request: &Request,
47 ) -> TardisApiResult<Vec<RbumRelBoneResp>> {
48 try_set_real_ip_from_req_to_ctx(request, &ctx.0).await?;
49 let funs = iam_constants::get_tardis_inst();
50 let result = IamResServ::find_from_simple_rel_roles(&IamRelKind::IamResRole, false, &id.0, desc_by_create.0, desc_by_update.0, &funs, &ctx.0).await?;
51 ctx.0.execute_task().await?;
52 TardisResp::ok(result)
53 }
54}