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