Skip to main content

openlark_workflow/v2/comment/
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 update;
13
14use openlark_core::config::Config;
15use std::sync::Arc;
16
17/// Comment:评论资源
18#[derive(Clone)]
19pub struct Comment {
20    config: Arc<Config>,
21    task_guid: String,
22}
23
24impl Comment {
25    /// 创建新的实例。
26    pub fn new(config: Arc<Config>) -> Self {
27        Self {
28            config,
29            task_guid: String::new(),
30        }
31    }
32
33    /// 绑定任务上下文。
34    pub fn with_task(mut self, task_guid: impl Into<String>) -> Self {
35        self.task_guid = task_guid.into();
36        self
37    }
38
39    /// 创建新建请求。
40    pub fn create(&self) -> create::CreateCommentRequest {
41        create::CreateCommentRequest::new(self.config.clone(), self.task_guid.clone())
42    }
43
44    /// 创建获取详情请求。
45    pub fn get(&self, comment_guid: impl Into<String>) -> get::GetCommentRequest {
46        get::GetCommentRequest::new(
47            self.config.clone(),
48            self.task_guid.clone(),
49            comment_guid.into(),
50        )
51    }
52
53    /// 创建更新请求。
54    pub fn update(&self, comment_guid: impl Into<String>) -> update::UpdateCommentRequest {
55        update::UpdateCommentRequest::new(
56            self.config.clone(),
57            self.task_guid.clone(),
58            comment_guid.into(),
59        )
60    }
61
62    /// 创建删除请求。
63    pub fn delete(&self, comment_guid: impl Into<String>) -> delete::DeleteCommentRequest {
64        delete::DeleteCommentRequest::new(
65            self.config.clone(),
66            self.task_guid.clone(),
67            comment_guid.into(),
68        )
69    }
70
71    /// 创建列表请求。
72    pub fn list(&self) -> list::ListCommentsRequest {
73        list::ListCommentsRequest::new(self.config.clone(), self.task_guid.clone())
74    }
75}
76
77// 重新导出请求类型
78pub use create::CreateCommentRequest;
79pub use delete::DeleteCommentRequest;
80pub use get::GetCommentRequest;
81pub use list::ListCommentsRequest;
82pub use update::UpdateCommentRequest;
83
84// 重新导出响应类型
85pub use models::{
86    CommentItem, CreateCommentBody, CreateCommentResponse, DeleteCommentResponse,
87    GetCommentResponse, ListCommentsResponse, UpdateCommentBody, UpdateCommentResponse,
88};
89
90#[cfg(test)]
91#[allow(unused_imports)]
92mod tests {
93    use super::*;
94    use std::sync::Arc;
95
96    fn create_test_config() -> Arc<Config> {
97        Arc::new(
98            Config::builder()
99                .app_id("test_app")
100                .app_secret("test_secret")
101                .build(),
102        )
103    }
104
105    #[test]
106    fn test_comment_new() {
107        let config = create_test_config();
108        let comment = Comment::new(config);
109        assert!(comment.task_guid.is_empty());
110    }
111
112    #[test]
113    fn test_comment_with_task() {
114        let config = create_test_config();
115        let comment = Comment::new(config).with_task("task_123");
116        assert_eq!(comment.task_guid, "task_123");
117    }
118
119    #[test]
120    fn test_comment_create() {
121        let config = create_test_config();
122        let comment = Comment::new(config).with_task("task_123");
123        let _request = comment.create();
124    }
125
126    #[test]
127    fn test_comment_get() {
128        let config = create_test_config();
129        let comment = Comment::new(config).with_task("task_123");
130        let _request = comment.get("comment_456");
131    }
132
133    #[test]
134    fn test_comment_update() {
135        let config = create_test_config();
136        let comment = Comment::new(config).with_task("task_123");
137        let _request = comment.update("comment_456");
138    }
139
140    #[test]
141    fn test_comment_delete() {
142        let config = create_test_config();
143        let comment = Comment::new(config).with_task("task_123");
144        let _request = comment.delete("comment_456");
145    }
146
147    #[test]
148    fn test_comment_list() {
149        let config = create_test_config();
150        let comment = Comment::new(config).with_task("task_123");
151        let _request = comment.list();
152    }
153}