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(self.config.clone(), comment_guid.into())
47    }
48
49    /// 创建更新请求。
50    pub fn update(&self, comment_guid: impl Into<String>) -> update::UpdateCommentRequest {
51        update::UpdateCommentRequest::new(self.config.clone(), comment_guid.into())
52    }
53
54    /// 创建删除请求。
55    pub fn delete(&self, comment_guid: impl Into<String>) -> delete::DeleteCommentRequest {
56        delete::DeleteCommentRequest::new(self.config.clone(), comment_guid.into())
57    }
58
59    /// 创建列表请求。
60    pub fn list(&self) -> list::ListCommentsRequest {
61        list::ListCommentsRequest::new(self.config.clone(), self.task_guid.clone())
62    }
63}
64
65// 重新导出请求类型
66pub use create::CreateCommentRequest;
67pub use delete::DeleteCommentRequest;
68pub use get::GetCommentRequest;
69pub use list::ListCommentsRequest;
70pub use update::UpdateCommentRequest;
71
72// 重新导出响应类型
73pub use models::{
74    CommentCreator, CommentItem, CreateCommentBody, CreateCommentResponse, DeleteCommentResponse,
75    GetCommentResponse, InputComment, ListCommentsResponse, UpdateCommentBody,
76    UpdateCommentResponse,
77};
78
79#[cfg(test)]
80#[allow(unused_imports)]
81mod tests {
82    use super::*;
83    use std::sync::Arc;
84
85    fn create_test_config() -> Arc<Config> {
86        Arc::new(
87            Config::builder()
88                .app_id("test_app")
89                .app_secret("test_secret")
90                .build(),
91        )
92    }
93
94    #[test]
95    fn test_comment_new() {
96        let config = create_test_config();
97        let comment = Comment::new(config);
98        assert!(comment.task_guid.is_empty());
99    }
100
101    #[test]
102    fn test_comment_with_task() {
103        let config = create_test_config();
104        let comment = Comment::new(config).with_task("task_123");
105        assert_eq!(comment.task_guid, "task_123");
106    }
107
108    #[test]
109    fn test_comment_create() {
110        let config = create_test_config();
111        let comment = Comment::new(config).with_task("task_123");
112        let _request = comment.create();
113    }
114
115    #[test]
116    fn test_comment_get() {
117        let config = create_test_config();
118        let comment = Comment::new(config).with_task("task_123");
119        let _request = comment.get("comment_456");
120    }
121
122    #[test]
123    fn test_comment_update() {
124        let config = create_test_config();
125        let comment = Comment::new(config).with_task("task_123");
126        let _request = comment.update("comment_456");
127    }
128
129    #[test]
130    fn test_comment_delete() {
131        let config = create_test_config();
132        let comment = Comment::new(config).with_task("task_123");
133        let _request = comment.delete("comment_456");
134    }
135
136    #[test]
137    fn test_comment_list() {
138        let config = create_test_config();
139        let comment = Comment::new(config).with_task("task_123");
140        let _request = comment.list();
141    }
142}