openlark_workflow/v1/task/comment/
list.rs1use openlark_core::{
6 api::{ApiRequest, ApiResponseTrait, ResponseFormat},
7 config::Config,
8 SDKResult,
9};
10use serde::Deserialize;
11use std::sync::Arc;
12
13#[derive(Debug, Clone, Deserialize)]
15pub struct TaskCommentItemV1 {
16 pub comment_id: String,
18 pub content: String,
20 pub creator_id: String,
22 pub created_at: Option<String>,
24 pub parent_id: Option<String>,
26}
27
28#[derive(Debug, Clone, Deserialize)]
30pub struct ListTaskCommentResponseV1 {
31 pub items: Vec<TaskCommentItemV1>,
33 pub has_more: Option<bool>,
35 pub page_token: Option<String>,
37}
38
39#[derive(Debug, Clone)]
41pub struct ListTaskCommentRequestV1 {
42 config: Arc<Config>,
43 task_id: String,
44 page_size: Option<i32>,
46 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 pub fn page_size(mut self, page_size: i32) -> Self {
62 self.page_size = Some(page_size);
63 self
64 }
65
66 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 pub async fn execute(self) -> SDKResult<ListTaskCommentResponseV1> {
74 self.execute_with_options(openlark_core::req_option::RequestOption::default())
75 .await
76 }
77
78 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}