Skip to main content

openlark_platform/
service.rs

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