openlark_workflow/v1/task/comment/
list.rs1use openlark_core::{
6 SDKResult,
7 api::{ApiRequest, ApiResponseTrait, ResponseFormat},
8 config::Config,
9};
10use serde::Deserialize;
11use std::sync::Arc;
12
13#[derive(Debug, Clone, Deserialize)]
15pub struct TaskCommentItemV1 {
17 pub comment_id: String,
19 pub content: String,
21 pub creator_id: String,
23 pub created_at: Option<String>,
25 pub parent_id: Option<String>,
27}
28
29#[derive(Debug, Clone, Deserialize)]
31pub struct ListTaskCommentResponseV1 {
33 pub items: Vec<TaskCommentItemV1>,
35 pub has_more: Option<bool>,
37 pub page_token: Option<String>,
39}
40
41#[derive(Debug, Clone)]
43pub struct ListTaskCommentRequestV1 {
45 config: Arc<Config>,
46 task_id: String,
47 page_size: Option<i32>,
49 page_token: Option<String>,
51}
52
53impl ListTaskCommentRequestV1 {
54 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 pub fn page_size(mut self, page_size: i32) -> Self {
66 self.page_size = Some(page_size);
67 self
68 }
69
70 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 pub async fn execute(self) -> SDKResult<ListTaskCommentResponseV1> {
78 self.execute_with_options(openlark_core::req_option::RequestOption::default())
79 .await
80 }
81
82 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}