Skip to main content

openlark_workflow/v1/task/comment/
list.rs

1//! 获取任务评论列表(v1)
2//!
3//! docPath: https://open.feishu.cn/document/server-docs/docs/task-v1/taskcomment/list
4
5use openlark_core::{
6    api::{ApiRequest, ApiResponseTrait, ResponseFormat},
7    config::Config,
8    SDKResult,
9};
10use serde::Deserialize;
11use std::sync::Arc;
12
13/// 任务评论列表项(v1)
14#[derive(Debug, Clone, Deserialize)]
15pub struct TaskCommentItemV1 {
16    /// 评论 ID
17    pub comment_id: String,
18    /// 评论内容
19    pub content: String,
20    /// 创建者用户 ID
21    pub creator_id: String,
22    /// 创建时间
23    pub created_at: Option<String>,
24    /// 父评论 ID
25    pub parent_id: Option<String>,
26}
27
28/// 获取任务评论列表响应(v1)
29#[derive(Debug, Clone, Deserialize)]
30pub struct ListTaskCommentResponseV1 {
31    /// 评论列表
32    pub items: Vec<TaskCommentItemV1>,
33    /// 是否有更多数据
34    pub has_more: Option<bool>,
35    /// 翻页标记
36    pub page_token: Option<String>,
37}
38
39/// 获取任务评论列表请求(v1)
40#[derive(Debug, Clone)]
41pub struct ListTaskCommentRequestV1 {
42    config: Arc<Config>,
43    task_id: String,
44    /// 每页数量
45    page_size: Option<i32>,
46    /// 翻页标记
47    page_token: Option<String>,
48}
49
50impl ListTaskCommentRequestV1 {
51    pub fn new(config: Arc<Config>, task_id: impl Into<String>) -> Self {
52        Self {
53            config,
54            task_id: task_id.into(),
55            page_size: None,
56            page_token: None,
57        }
58    }
59
60    /// 设置每页数量
61    pub fn page_size(mut self, page_size: i32) -> Self {
62        self.page_size = Some(page_size);
63        self
64    }
65
66    /// 设置翻页标记
67    pub fn page_token(mut self, page_token: impl Into<String>) -> Self {
68        self.page_token = Some(page_token.into());
69        self
70    }
71
72    /// 执行请求
73    pub async fn execute(self) -> SDKResult<ListTaskCommentResponseV1> {
74        self.execute_with_options(openlark_core::req_option::RequestOption::default())
75            .await
76    }
77
78    /// 执行请求(带选项)
79    pub async fn execute_with_options(
80        self,
81        option: openlark_core::req_option::RequestOption,
82    ) -> SDKResult<ListTaskCommentResponseV1> {
83        let api_endpoint =
84            crate::common::api_endpoints::TaskApiV1::TaskCommentList(self.task_id.clone());
85        let mut request = ApiRequest::<ListTaskCommentResponseV1>::get(api_endpoint.to_url());
86
87        if let Some(page_size) = self.page_size {
88            request = request.query("page_size", page_size.to_string());
89        }
90        if let Some(page_token) = self.page_token {
91            request = request.query("page_token", page_token);
92        }
93
94        let response =
95            openlark_core::http::Transport::request(request, &self.config, Some(option)).await?;
96        response.data.ok_or_else(|| {
97            openlark_core::error::validation_error("响应数据为空", "服务器没有返回有效的数据")
98        })
99    }
100}
101
102impl ApiResponseTrait for ListTaskCommentResponseV1 {
103    fn data_format() -> ResponseFormat {
104        ResponseFormat::Data
105    }
106}
107
108#[cfg(test)]
109#[allow(unused_imports)]
110mod tests {
111
112    #[test]
113    fn test_list_task_comment_v1_url() {
114        let endpoint =
115            crate::common::api_endpoints::TaskApiV1::TaskCommentList("task_123".to_string());
116        assert_eq!(
117            endpoint.to_url(),
118            "/open-apis/task/v1/tasks/task_123/comments"
119        );
120    }
121}