Skip to main content

openlark_workflow/v2/
mod.rs

1//! 任务 v2 入口模块
2//!
3//! 提供任务 API v2 的统一访问入口,聚合任务、任务清单、自定义字段、评论、分组与附件能力。
4//!
5//! ## 主要功能
6//! - `task`: 任务资源模块入口
7//! - `tasklist` / `custom_field`: 任务清单与自定义字段能力
8//! - `comment` / `section` / `attachment`: 评论、分组与附件能力
9
10/// 附件模块。
11pub mod attachment;
12/// 评论模块。
13pub mod comment;
14/// 自定义字段模块。
15pub mod custom_field;
16/// 分组模块。
17pub mod section;
18/// 任务模块。
19pub mod task;
20/// 任务清单模块。
21pub mod tasklist;
22
23use openlark_core::config::Config;
24use std::sync::Arc;
25
26/// TaskV2:任务 API v2 访问入口
27#[derive(Clone)]
28pub struct TaskV2 {
29    config: Arc<Config>,
30}
31
32impl TaskV2 {
33    /// 创建新的任务 v2 API 入口。
34    pub fn new(config: Arc<Config>) -> Self {
35        Self { config }
36    }
37
38    /// 访问任务资源
39    pub fn task(&self) -> task::Task {
40        task::Task::new(self.config.clone())
41    }
42
43    /// 访问任务清单资源
44    pub fn tasklist(&self) -> tasklist::Tasklist {
45        tasklist::Tasklist::new(self.config.clone())
46    }
47
48    /// 访问自定义字段资源
49    pub fn custom_field(&self) -> custom_field::CustomField {
50        custom_field::CustomField::new(self.config.clone())
51    }
52
53    /// 访问评论资源
54    pub fn comment(&self) -> comment::Comment {
55        comment::Comment::new(self.config.clone())
56    }
57
58    /// 访问分组资源
59    pub fn section(&self) -> section::Section {
60        section::Section::new(self.config.clone())
61    }
62
63    /// 访问附件资源
64    pub fn attachment(&self) -> attachment::Attachment {
65        attachment::Attachment::new(self.config.clone())
66    }
67}
68
69#[cfg(test)]
70#[allow(unused_imports)]
71mod tests {
72    use super::*;
73    use std::sync::Arc;
74
75    fn create_test_config() -> Arc<Config> {
76        Arc::new(
77            Config::builder()
78                .app_id("test_app")
79                .app_secret("test_secret")
80                .build(),
81        )
82    }
83
84    #[test]
85    fn test_task_v2_new() {
86        let config = create_test_config();
87        let _task_v2 = TaskV2::new(config);
88    }
89
90    #[test]
91    fn test_task_v2_task() {
92        let config = create_test_config();
93        let task_v2 = TaskV2::new(config);
94        let _task = task_v2.task();
95    }
96
97    #[test]
98    fn test_task_v2_tasklist() {
99        let config = create_test_config();
100        let task_v2 = TaskV2::new(config);
101        let _tasklist = task_v2.tasklist();
102    }
103
104    #[test]
105    fn test_task_v2_custom_field() {
106        let config = create_test_config();
107        let task_v2 = TaskV2::new(config);
108        let _custom_field = task_v2.custom_field();
109    }
110
111    #[test]
112    fn test_task_v2_comment() {
113        let config = create_test_config();
114        let task_v2 = TaskV2::new(config);
115        let _comment = task_v2.comment();
116    }
117
118    #[test]
119    fn test_task_v2_section() {
120        let config = create_test_config();
121        let task_v2 = TaskV2::new(config);
122        let _section = task_v2.section();
123    }
124
125    #[test]
126    fn test_task_v2_attachment() {
127        let config = create_test_config();
128        let task_v2 = TaskV2::new(config);
129        let _attachment = task_v2.attachment();
130    }
131}