Skip to main content

openlark_workflow/v2/tasklist/
get.rs

1//! 获取任务清单详情
2//!
3//! docPath: https://open.feishu.cn/document/server-docs/docs/task-v2/tasklist/get
4
5use crate::common::{api_endpoints::TaskApiV2, api_utils::*};
6use crate::v2::tasklist::models::GetTasklistResponse;
7use openlark_core::{
8    SDKResult,
9    api::{ApiRequest, ApiResponseTrait, ResponseFormat},
10    config::Config,
11    validate_required,
12};
13use std::sync::Arc;
14
15/// 获取任务清单请求
16#[derive(Debug, Clone)]
17pub struct GetTasklistRequest {
18    /// 配置信息
19    config: Arc<Config>,
20    /// 任务清单 GUID
21    tasklist_guid: String,
22}
23
24impl GetTasklistRequest {
25    /// 创建新的请求构建器。
26    pub fn new(config: Arc<Config>, tasklist_guid: String) -> Self {
27        Self {
28            config,
29            tasklist_guid,
30        }
31    }
32
33    /// 执行请求
34    pub async fn execute(self) -> SDKResult<GetTasklistResponse> {
35        self.execute_with_options(openlark_core::req_option::RequestOption::default())
36            .await
37    }
38
39    /// 执行请求(带选项)
40    pub async fn execute_with_options(
41        self,
42        option: openlark_core::req_option::RequestOption,
43    ) -> SDKResult<GetTasklistResponse> {
44        // 验证必填字段
45        validate_required!(self.tasklist_guid.trim(), "任务清单GUID不能为空");
46
47        let api_endpoint = TaskApiV2::TasklistGet(self.tasklist_guid.clone());
48        let request = ApiRequest::<GetTasklistResponse>::get(api_endpoint.to_url());
49
50        let response =
51            openlark_core::http::Transport::request(request, &self.config, Some(option)).await?;
52        extract_response_data(response, "获取任务清单")
53    }
54}
55
56impl ApiResponseTrait for GetTasklistResponse {
57    fn data_format() -> ResponseFormat {
58        ResponseFormat::Data
59    }
60}
61
62#[cfg(test)]
63#[allow(unused_imports)]
64mod tests {
65    use std::sync::Arc;
66
67    use super::*;
68
69    #[test]
70    fn test_get_tasklist_request() {
71        let config = openlark_core::config::Config::builder()
72            .app_id("test")
73            .app_secret("test")
74            .build();
75
76        let request = GetTasklistRequest::new(Arc::new(config), "tasklist_123".to_string());
77
78        assert_eq!(request.tasklist_guid, "tasklist_123");
79    }
80}