Skip to main content

openlark_workflow/v2/section/
get.rs

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