Skip to main content

openlark_workflow/v2/tasklist/
delete.rs

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