Skip to main content

openlark_platform/
admin.rs

1//! 系统管理模块
2//!
3//! 提供系统配置、后台管理、平台工具等功能 (14 APIs)
4
5use crate::PlatformConfig;
6use std::sync::Arc;
7
8/// 系统管理服务
9///
10/// 提供系统管理相关 API 的访问入口。
11#[derive(Debug, Clone)]
12pub struct AdminService {
13    /// 客户端配置
14    config: Arc<PlatformConfig>,
15}
16
17impl AdminService {
18    /// 创建新的系统管理服务实例
19    pub fn new(config: Arc<PlatformConfig>) -> Self {
20        Self { config }
21    }
22
23    /// 获取客户端配置
24    pub fn config(&self) -> Arc<PlatformConfig> {
25        self.config.clone()
26    }
27
28    /// V1 版本 API
29    #[cfg(feature = "v1")]
30    pub fn v1(&self) -> crate::admin::admin::v1::AdminV1 {
31        crate::admin::admin::v1::AdminV1::new(self.config.clone())
32    }
33}
34
35#[cfg(feature = "v1")]
36pub mod admin;
37
38#[cfg(test)]
39mod tests {
40    use crate::{PlatformConfig, admin::AdminService};
41
42    #[test]
43    fn test_service_creation() {
44        let config = PlatformConfig::builder()
45            .app_id("test_app_id")
46            .app_secret("test_app_secret")
47            .build();
48
49        let service = AdminService::new(std::sync::Arc::new(config));
50        // PlatformConfig 实现了 Deref,可以直接访问 app_id
51        assert_eq!(service.config().app_id(), "test_app_id");
52    }
53}