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