Skip to main content

openlark_workflow/v2/comment/
mod.rs

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