Skip to main content

openlark_platform/admin/v1/
mod.rs

1//! 管理后台 V1 API
2//!
3//! 提供管理后台 V1 版本的 API 访问。
4
5use crate::PlatformConfig;
6use std::sync::Arc;
7
8/// 部门维度统计接口。
9pub mod admin_dept_stat;
10/// 用户维度统计接口。
11pub mod admin_user_stat;
12/// 审计兼容 facade。
13pub mod audit;
14/// 审计信息查询接口。
15pub mod audit_info;
16/// 勋章管理接口。
17pub mod badge;
18/// 勋章图片上传接口。
19pub mod badge_image;
20/// 密码重置接口。
21pub mod password;
22/// 用户管理兼容 facade。
23pub mod users;
24
25/// 管理后台 V1 API
26#[derive(Debug, Clone)]
27pub struct AdminV1 {
28    config: Arc<PlatformConfig>,
29}
30
31impl AdminV1 {
32    /// 创建新的管理后台 V1 实例。
33    pub fn new(config: Arc<PlatformConfig>) -> Self {
34        Self { config }
35    }
36
37    /// badge 资源
38    pub fn badge(&self) -> badge::BadgeService {
39        badge::BadgeService::new(self.config.as_ref().clone())
40    }
41
42    /// badge_image 资源
43    pub fn badge_image(&self) -> badge_image::BadgeImageService {
44        badge_image::BadgeImageService::new(self.config.as_ref().clone())
45    }
46
47    /// password 资源
48    pub fn password(&self) -> password::PasswordService {
49        password::PasswordService::new(self.config.as_ref().clone())
50    }
51
52    /// admin_dept_stat 资源
53    pub fn admin_dept_stat(&self) -> admin_dept_stat::AdminDeptStatService {
54        admin_dept_stat::AdminDeptStatService::new(self.config.as_ref().clone())
55    }
56
57    /// admin_user_stat 资源
58    pub fn admin_user_stat(&self) -> admin_user_stat::AdminUserStatService {
59        admin_user_stat::AdminUserStatService::new(self.config.as_ref().clone())
60    }
61
62    /// audit_info 资源
63    pub fn audit_info(&self) -> audit_info::AuditInfoService {
64        audit_info::AuditInfoService::new(self.config.as_ref().clone())
65    }
66
67    /// audit facade(D5:复用已有 AuditApi stub 类型)
68    pub fn audit(&self) -> audit::AuditApi {
69        audit::AuditApi::new(self.config.clone())
70    }
71
72    /// users facade(D5:复用已有 UsersApi stub 类型)
73    pub fn users(&self) -> users::UsersApi {
74        users::UsersApi::new(self.config.clone())
75    }
76}
77
78#[cfg(test)]
79mod tests {
80    use super::AdminV1;
81    use crate::PlatformConfig;
82
83    #[test]
84    fn test_admin_v1_creation() {
85        let config = PlatformConfig::builder()
86            .app_id("test_app_id")
87            .app_secret("test_app_secret")
88            .build();
89
90        let api = AdminV1::new(std::sync::Arc::new(config));
91        assert_eq!(api.config.app_id(), "test_app_id");
92    }
93
94    #[test]
95    fn test_admin_v1_chain_access() {
96        let config = PlatformConfig::builder()
97            .app_id("test_app_id")
98            .app_secret("test_app_secret")
99            .build();
100        let api = AdminV1::new(std::sync::Arc::new(config));
101        // 6 操作集合叶子 builder 可达
102        let _ = api.badge().create();
103        let _ = api.badge().list();
104        let _ = api.badge_image().create();
105        let _ = api.password().reset();
106        let _ = api.admin_dept_stat().list();
107        let _ = api.admin_user_stat().list();
108        let _ = api.audit_info().list();
109        // badge.grant 深一级
110        let _ = api.badge().grant().list();
111        // 2 facade(D5:返回已有 AuditApi/UsersApi stub 类型)
112        let _ = api.audit();
113        let _ = api.users();
114    }
115}