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