bios_iam/console_app/api/
iam_ca_app_api.rs1use bios_basic::process::task_processor::TaskProcessor;
2use tardis::web::context_extractor::TardisContextExtractor;
3use tardis::web::poem_openapi;
4use tardis::web::poem_openapi::{param::Path, payload::Json};
5use tardis::web::web_resp::{TardisApiResult, TardisResp, Void};
6
7use bios_basic::rbum::serv::rbum_item_serv::RbumItemCrudOperation;
8
9use crate::basic::dto::iam_app_dto::{IamAppAggModifyReq, IamAppDetailResp};
10use crate::basic::dto::iam_filer_dto::IamAppFilterReq;
11use crate::basic::serv::iam_app_serv::IamAppServ;
12use crate::iam_constants;
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 IamCaAppApi;
17
18#[poem_openapi::OpenApi(prefix_path = "/ca/app", tag = "bios_basic::ApiTag::App")]
21impl IamCaAppApi {
22 #[oai(path = "/", method = "put")]
28 async fn modify(&self, modify_req: Json<IamAppAggModifyReq>, ctx: TardisContextExtractor, request: &Request) -> TardisApiResult<Option<String>> {
29 try_set_real_ip_from_req_to_ctx(request, &ctx.0).await?;
30 let mut funs = iam_constants::get_tardis_inst();
31 funs.begin().await?;
32 IamAppServ::modify_app_agg(&IamAppServ::get_id_by_ctx(&ctx.0, &funs)?, &modify_req, &funs, &ctx.0).await?;
33 funs.commit().await?;
34 ctx.0.execute_task().await?;
35 if let Some(task_id) = TaskProcessor::get_task_id_with_ctx(&ctx.0).await? {
36 TardisResp::accepted(Some(task_id))
37 } else {
38 TardisResp::ok(None)
39 }
40 }
41
42 #[oai(path = "/", method = "get")]
45 async fn get(&self, ctx: TardisContextExtractor, request: &Request) -> TardisApiResult<IamAppDetailResp> {
46 try_set_real_ip_from_req_to_ctx(request, &ctx.0).await?;
47 let funs = iam_constants::get_tardis_inst();
48 let result = IamAppServ::get_item(&IamAppServ::get_id_by_ctx(&ctx.0, &funs)?, &IamAppFilterReq::default(), &funs, &ctx.0).await?;
49 ctx.0.execute_task().await?;
50 TardisResp::ok(result)
51 }
52
53 #[oai(path = "/:id/account/:account_id", method = "put")]
56 async fn add_rel_account(&self, id: Path<String>, account_id: Path<String>, ctx: TardisContextExtractor, request: &Request) -> TardisApiResult<Void> {
57 try_set_real_ip_from_req_to_ctx(request, &ctx.0).await?;
58 let mut funs = iam_constants::get_tardis_inst();
59 funs.begin().await?;
60 IamAppServ::add_rel_account(&id.0, &account_id.0, false, &funs, &ctx.0).await?;
61 funs.commit().await?;
62 TardisResp::ok(Void {})
63 }
64
65 #[oai(path = "/:id/account/:account_id", method = "delete")]
68 async fn delete_rel_account(&self, id: Path<String>, account_id: Path<String>, ctx: TardisContextExtractor, request: &Request) -> TardisApiResult<Void> {
69 try_set_real_ip_from_req_to_ctx(request, &ctx.0).await?;
70 let mut funs = iam_constants::get_tardis_inst();
71 funs.begin().await?;
72 IamAppServ::delete_rel_account(&id.0, &account_id.0, &funs, &ctx.0).await?;
73 funs.commit().await?;
74 ctx.0.execute_task().await?;
75 TardisResp::ok(Void {})
76 }
77
78 #[oai(path = "/:id/account/batch/:account_ids", method = "delete")]
81 async fn batch_delete_rel_account(&self, id: Path<String>, account_ids: Path<String>, ctx: TardisContextExtractor, request: &Request) -> TardisApiResult<Void> {
82 try_set_real_ip_from_req_to_ctx(request, &ctx.0).await?;
83 let mut funs = iam_constants::get_tardis_inst();
84 funs.begin().await?;
85 let split = account_ids.0.split(',').collect::<Vec<_>>();
86 for s in split {
87 IamAppServ::delete_rel_account(&id.0, s, &funs, &ctx.0).await?;
88 }
89 funs.commit().await?;
90 ctx.0.execute_task().await?;
91 TardisResp::ok(Void {})
92 }
93}