Skip to main content

openlark_platform/
service.rs

1//! 平台服务
2//!
3//! 提供平台管理相关的服务入口
4
5use crate::PlatformConfig;
6use std::sync::Arc;
7
8/// 平台服务
9///
10/// 提供应用引擎、目录服务、系统管理等功能的统一入口。
11#[derive(Debug, Clone)]
12pub struct PlatformService {
13    /// 客户端配置
14    config: Arc<PlatformConfig>,
15}
16
17impl PlatformService {
18    /// 创建新的平台服务实例
19    ///
20    /// # 参数
21    ///
22    /// * `config` - 平台服务配置
23    pub fn new(config: PlatformConfig) -> Self {
24        Self {
25            config: Arc::new(config),
26        }
27    }
28
29    /// 获取客户端配置
30    pub fn config(&self) -> Arc<PlatformConfig> {
31        self.config.clone()
32    }
33
34    /// 应用引擎服务
35    ///
36    /// 提供应用管理、多租户、应用市场等功能。
37    #[cfg(feature = "app-engine")]
38    pub fn app_engine(&self) -> crate::app_engine::AppEngineService {
39        crate::app_engine::AppEngineService::new(self.config.clone())
40    }
41
42    /// 目录服务
43    ///
44    /// 提供用户搜索、组织目录、人员查找等功能。
45    #[cfg(feature = "directory")]
46    pub fn directory(&self) -> crate::directory::DirectoryService {
47        crate::directory::DirectoryService::new(self.config.clone())
48    }
49
50    /// 系统管理服务
51    ///
52    /// 提供系统配置、后台管理、平台工具等功能。
53    #[cfg(feature = "admin")]
54    pub fn admin(&self) -> crate::admin::AdminService {
55        crate::admin::AdminService::new(self.config.clone())
56    }
57
58    /// 妙搭平台服务
59    ///
60    /// 提供妙搭和开放平台用户 ID 转换等功能。
61    #[cfg(feature = "spark")]
62    pub fn spark(&self) -> crate::spark::SparkService {
63        crate::spark::SparkService::new(self.config.clone())
64    }
65}
66
67#[cfg(test)]
68mod tests {
69    use crate::{PlatformConfig, PlatformService};
70
71    #[test]
72    fn test_service_creation() {
73        let config = PlatformConfig::builder()
74            .app_id("test_app_id")
75            .app_secret("test_app_secret")
76            .build();
77        let _service = PlatformService::new(config);
78    }
79}