Skip to main content

openlark_workflow/v2/section/
mod.rs

1/// 创建接口。
2pub mod create;
3/// 删除接口。
4pub mod delete;
5/// 获取接口。
6pub mod get;
7/// 列表接口。
8pub mod list;
9/// 数据模型。
10pub mod models;
11/// 更新接口。
12pub mod patch;
13/// 更新接口。
14pub mod update;
15
16use openlark_core::config::Config;
17use std::sync::Arc;
18
19/// Section:分组资源
20#[derive(Clone)]
21pub struct Section {
22    config: Arc<Config>,
23    tasklist_guid: String,
24}
25
26impl Section {
27    /// 创建新的实例。
28    pub fn new(config: Arc<Config>) -> Self {
29        Self {
30            config,
31            tasklist_guid: String::new(),
32        }
33    }
34
35    /// 绑定任务清单上下文。
36    pub fn with_tasklist(mut self, tasklist_guid: impl Into<String>) -> Self {
37        self.tasklist_guid = tasklist_guid.into();
38        self
39    }
40
41    /// 创建新建请求。
42    pub fn create(&self) -> create::CreateSectionRequest {
43        create::CreateSectionRequest::new(self.config.clone(), self.tasklist_guid.clone())
44    }
45
46    /// 创建获取详情请求。
47    pub fn get(&self, section_guid: impl Into<String>) -> get::GetSectionRequest {
48        get::GetSectionRequest::new(
49            self.config.clone(),
50            self.tasklist_guid.clone(),
51            section_guid.into(),
52        )
53    }
54
55    /// 创建更新请求。
56    pub fn update(&self, section_guid: impl Into<String>) -> update::UpdateSectionRequest {
57        update::UpdateSectionRequest::new(
58            self.config.clone(),
59            self.tasklist_guid.clone(),
60            section_guid.into(),
61        )
62    }
63
64    /// 创建删除请求。
65    pub fn delete(&self, section_guid: impl Into<String>) -> delete::DeleteSectionRequest {
66        delete::DeleteSectionRequest::new(
67            self.config.clone(),
68            self.tasklist_guid.clone(),
69            section_guid.into(),
70        )
71    }
72
73    /// 创建列表请求。
74    pub fn list(&self) -> list::ListSectionsRequest {
75        list::ListSectionsRequest::new(self.config.clone(), self.tasklist_guid.clone())
76    }
77}
78
79// 重新导出请求类型
80pub use create::CreateSectionRequest;
81pub use delete::DeleteSectionRequest;
82pub use get::GetSectionRequest;
83pub use list::ListSectionsRequest;
84pub use patch::UpdateSectionRequest;
85
86// 重新导出响应类型
87pub use models::{
88    CreateSectionBody, CreateSectionResponse, DeleteSectionResponse, GetSectionResponse,
89    ListSectionsResponse, SectionItem, UpdateSectionBody, UpdateSectionResponse,
90};
91
92#[cfg(test)]
93#[allow(unused_imports)]
94mod tests {
95    use super::*;
96    use std::sync::Arc;
97
98    fn create_test_config() -> Arc<Config> {
99        Arc::new(
100            Config::builder()
101                .app_id("test_app")
102                .app_secret("test_secret")
103                .build(),
104        )
105    }
106
107    #[test]
108    fn test_section_new() {
109        let config = create_test_config();
110        let section = Section::new(config);
111        assert!(section.tasklist_guid.is_empty());
112    }
113
114    #[test]
115    fn test_section_with_tasklist() {
116        let config = create_test_config();
117        let section = Section::new(config).with_tasklist("tasklist_123");
118        assert_eq!(section.tasklist_guid, "tasklist_123");
119    }
120
121    #[test]
122    fn test_section_create() {
123        let config = create_test_config();
124        let section = Section::new(config).with_tasklist("tasklist_123");
125        let _request = section.create();
126    }
127
128    #[test]
129    fn test_section_get() {
130        let config = create_test_config();
131        let section = Section::new(config).with_tasklist("tasklist_123");
132        let _request = section.get("section_456");
133    }
134
135    #[test]
136    fn test_section_update() {
137        let config = create_test_config();
138        let section = Section::new(config).with_tasklist("tasklist_123");
139        let _request = section.update("section_456");
140    }
141
142    #[test]
143    fn test_section_delete() {
144        let config = create_test_config();
145        let section = Section::new(config).with_tasklist("tasklist_123");
146        let _request = section.delete("section_456");
147    }
148
149    #[test]
150    fn test_section_list() {
151        let config = create_test_config();
152        let section = Section::new(config).with_tasklist("tasklist_123");
153        let _request = section.list();
154    }
155}