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