openlark_workflow/v1/task/follower/
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 TaskFollowerItemV1 {
16 pub follower_id: String,
18 pub name: Option<String>,
20}
21
22#[derive(Debug, Clone, Deserialize)]
24pub struct ListTaskFollowerResponseV1 {
25 pub items: Vec<TaskFollowerItemV1>,
27 pub has_more: Option<bool>,
29 pub page_token: Option<String>,
31}
32
33#[derive(Debug, Clone)]
35pub struct ListTaskFollowerRequestV1 {
36 config: Arc<Config>,
37 task_id: String,
38 page_size: Option<i32>,
40 page_token: Option<String>,
42}
43
44impl ListTaskFollowerRequestV1 {
45 pub fn new(config: Arc<Config>, task_id: impl Into<String>) -> Self {
46 Self {
47 config,
48 task_id: task_id.into(),
49 page_size: None,
50 page_token: None,
51 }
52 }
53
54 pub fn page_size(mut self, page_size: i32) -> Self {
56 self.page_size = Some(page_size);
57 self
58 }
59
60 pub fn page_token(mut self, page_token: impl Into<String>) -> Self {
62 self.page_token = Some(page_token.into());
63 self
64 }
65
66 pub async fn execute(self) -> SDKResult<ListTaskFollowerResponseV1> {
68 self.execute_with_options(openlark_core::req_option::RequestOption::default())
69 .await
70 }
71
72 pub async fn execute_with_options(
74 self,
75 option: openlark_core::req_option::RequestOption,
76 ) -> SDKResult<ListTaskFollowerResponseV1> {
77 let api_endpoint =
78 crate::common::api_endpoints::TaskApiV1::TaskFollowerList(self.task_id.clone());
79 let mut request = ApiRequest::<ListTaskFollowerResponseV1>::get(api_endpoint.to_url());
80
81 if let Some(page_size) = self.page_size {
82 request = request.query("page_size", page_size.to_string());
83 }
84 if let Some(page_token) = self.page_token {
85 request = request.query("page_token", page_token);
86 }
87
88 let response =
89 openlark_core::http::Transport::request(request, &self.config, Some(option)).await?;
90 response.data.ok_or_else(|| {
91 openlark_core::error::validation_error("响应数据为空", "服务器没有返回有效的数据")
92 })
93 }
94}
95
96impl ApiResponseTrait for ListTaskFollowerResponseV1 {
97 fn data_format() -> ResponseFormat {
98 ResponseFormat::Data
99 }
100}
101
102#[cfg(test)]
103#[allow(unused_imports)]
104mod tests {
105
106 #[test]
107 fn test_list_task_follower_v1_url() {
108 let endpoint =
109 crate::common::api_endpoints::TaskApiV1::TaskFollowerList("task_123".to_string());
110 assert_eq!(
111 endpoint.to_url(),
112 "/open-apis/task/v1/tasks/task_123/followers"
113 );
114 }
115}