Skip to main content

openlark_workflow/v1/task/follower/
list.rs

1//! 获取任务关注者列表(v1)
2//!
3//! docPath: https://open.feishu.cn/document/server-docs/docs/task-v1/taskfollower/list
4
5use openlark_core::{
6    api::{ApiRequest, ApiResponseTrait, ResponseFormat},
7    config::Config,
8    SDKResult,
9};
10use serde::Deserialize;
11use std::sync::Arc;
12
13/// 任务关注者列表项(v1)
14#[derive(Debug, Clone, Deserialize)]
15pub struct TaskFollowerItemV1 {
16    /// 关注者用户 ID
17    pub follower_id: String,
18    /// 关注者名称
19    pub name: Option<String>,
20}
21
22/// 获取任务关注者列表响应(v1)
23#[derive(Debug, Clone, Deserialize)]
24pub struct ListTaskFollowerResponseV1 {
25    /// 关注者列表
26    pub items: Vec<TaskFollowerItemV1>,
27    /// 是否有更多数据
28    pub has_more: Option<bool>,
29    /// 翻页标记
30    pub page_token: Option<String>,
31}
32
33/// 获取任务关注者列表请求(v1)
34#[derive(Debug, Clone)]
35pub struct ListTaskFollowerRequestV1 {
36    config: Arc<Config>,
37    task_id: String,
38    /// 每页数量
39    page_size: Option<i32>,
40    /// 翻页标记
41    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    /// 设置每页数量
55    pub fn page_size(mut self, page_size: i32) -> Self {
56        self.page_size = Some(page_size);
57        self
58    }
59
60    /// 设置翻页标记
61    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    /// 执行请求
67    pub async fn execute(self) -> SDKResult<ListTaskFollowerResponseV1> {
68        self.execute_with_options(openlark_core::req_option::RequestOption::default())
69            .await
70    }
71
72    /// 执行请求(带选项)
73    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}