Skip to main content

openlark_platform/directory/v1/
mod.rs

1//! 目录服务 V1 API
2//!
3//! 提供目录服务 V1 版本的 API 访问
4
5use crate::PlatformConfig;
6use std::sync::Arc;
7
8/// 可搜可见规则接口。
9pub mod collaboration_rule;
10/// 关联组织共享实体查询接口。
11pub mod collaboration_share_entity;
12/// 关联组织列表接口。
13pub mod collaboration_tenant;
14/// 部门写操作与查询接口。
15pub mod department;
16/// 部门兼容 facade。
17pub mod departments;
18/// 员工写操作与查询接口。
19pub mod employee;
20/// 同步相关接口。
21pub mod sync;
22/// 用户兼容 facade。
23pub mod users;
24
25/// 目录服务 V1 API
26#[derive(Debug, Clone)]
27pub struct DirectoryV1 {
28    config: Arc<PlatformConfig>,
29}
30
31impl DirectoryV1 {
32    /// 创建新的目录服务 V1 实例
33    pub fn new(config: Arc<PlatformConfig>) -> Self {
34        Self { config }
35    }
36
37    /// department 资源
38    pub fn department(&self) -> department::DepartmentService {
39        department::DepartmentService::new(self.config.as_ref().clone())
40    }
41
42    /// employee 资源
43    pub fn employee(&self) -> employee::EmployeeService {
44        employee::EmployeeService::new(self.config.as_ref().clone())
45    }
46
47    /// collaboration_rule 资源
48    pub fn collaboration_rule(&self) -> collaboration_rule::CollaborationRuleService {
49        collaboration_rule::CollaborationRuleService::new(self.config.as_ref().clone())
50    }
51
52    /// collaboration_share_entity 资源
53    pub fn collaboration_share_entity(
54        &self,
55    ) -> collaboration_share_entity::CollaborationShareEntityService {
56        collaboration_share_entity::CollaborationShareEntityService::new(
57            self.config.as_ref().clone(),
58        )
59    }
60
61    /// collaboration_tenant 资源
62    pub fn collaboration_tenant(&self) -> collaboration_tenant::CollaborationTenantService {
63        collaboration_tenant::CollaborationTenantService::new(self.config.as_ref().clone())
64    }
65}
66
67#[cfg(test)]
68mod tests {
69    use super::DirectoryV1;
70    use crate::PlatformConfig;
71
72    #[test]
73    fn test_directory_v1_creation() {
74        let config = PlatformConfig::builder()
75            .app_id("test_app_id")
76            .app_secret("test_app_secret")
77            .build();
78
79        let api = DirectoryV1::new(std::sync::Arc::new(config));
80        assert_eq!(api.config.app_id(), "test_app_id");
81    }
82
83    #[test]
84    fn test_directory_v1_chain_access() {
85        let config = PlatformConfig::builder()
86            .app_id("test_app_id")
87            .app_secret("test_app_secret")
88            .build();
89        let api = DirectoryV1::new(std::sync::Arc::new(config));
90        // department(create 带 name,patch/delete 带 department_id,search 带 keyword)
91        let _ = api.department().create("test_dept".to_string());
92        let _ = api.department().filter();
93        let _ = api.department().mget();
94        let _ = api.department().patch("dept_id".to_string());
95        let _ = api.department().delete("dept_id".to_string());
96        let _ = api.department().search("kw".to_string());
97        // employee(create 带 name+mobile,其余带 employee_id 或 keyword)
98        let _ = api.employee().create("n".to_string(), "m".to_string());
99        let _ = api.employee().filter();
100        let _ = api.employee().mget();
101        let _ = api.employee().patch("eid".to_string());
102        let _ = api.employee().delete("eid".to_string());
103        let _ = api.employee().regular("eid".to_string());
104        let _ = api.employee().resurrect("eid".to_string());
105        let _ = api.employee().search("kw".to_string());
106        let _ = api.employee().to_be_resigned("eid".to_string());
107        // collaboration_rule(create 带 name,update/delete 带 rule_id)
108        let _ = api.collaboration_rule().create("rule".to_string());
109        let _ = api.collaboration_rule().list();
110        let _ = api.collaboration_rule().update("rid".to_string());
111        let _ = api.collaboration_rule().delete("rid".to_string());
112        // 单 list 模块
113        let _ = api.collaboration_share_entity().list();
114        let _ = api.collaboration_tenant().list();
115    }
116}