Skip to main content

openlark_workflow/v2/section/
mod.rs

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