Skip to main content

openlark_workflow/v1/task/
delete.rs

1//! 删除任务(v1)
2//!
3//! docPath: https://open.feishu.cn/document/server-docs/docs/task-v1/task/delete
4
5use openlark_core::{
6    SDKResult,
7    api::{ApiRequest, ApiResponseTrait, ResponseFormat},
8    config::Config,
9};
10use serde::Deserialize;
11use std::sync::Arc;
12
13/// 删除任务响应(v1)
14#[derive(Debug, Clone, Deserialize)]
15/// 删除任务响应。
16pub struct DeleteTaskResponseV1 {
17    /// 删除结果
18    pub success: bool,
19}
20
21/// 删除任务请求(v1)
22#[derive(Debug, Clone)]
23/// 删除任务请求构建器。
24pub struct DeleteTaskRequestV1 {
25    config: Arc<Config>,
26    task_id: String,
27}
28
29impl DeleteTaskRequestV1 {
30    /// 创建新的请求构建器。
31    pub fn new(config: Arc<Config>, task_id: impl Into<String>) -> Self {
32        Self {
33            config,
34            task_id: task_id.into(),
35        }
36    }
37
38    /// 执行请求
39    pub async fn execute(self) -> SDKResult<DeleteTaskResponseV1> {
40        self.execute_with_options(openlark_core::req_option::RequestOption::default())
41            .await
42    }
43
44    /// 执行请求(带选项)
45    pub async fn execute_with_options(
46        self,
47        option: openlark_core::req_option::RequestOption,
48    ) -> SDKResult<DeleteTaskResponseV1> {
49        let api_endpoint = crate::common::api_endpoints::TaskApiV1::TaskDelete(self.task_id);
50        let request = ApiRequest::<DeleteTaskResponseV1>::delete(api_endpoint.to_url());
51
52        let response =
53            openlark_core::http::Transport::request(request, &self.config, Some(option)).await?;
54        response.data.ok_or_else(|| {
55            openlark_core::error::validation_error("响应数据为空", "服务器没有返回有效的数据")
56        })
57    }
58}
59
60impl ApiResponseTrait for DeleteTaskResponseV1 {
61    fn data_format() -> ResponseFormat {
62        ResponseFormat::Data
63    }
64}
65
66#[cfg(test)]
67#[allow(unused_imports)]
68mod tests {
69    use std::sync::Arc;
70
71    use super::*;
72
73    #[test]
74    fn test_delete_task_v1_builder() {
75        let config = Arc::new(
76            openlark_core::config::Config::builder()
77                .app_id("test")
78                .app_secret("test")
79                .build(),
80        );
81
82        let request = DeleteTaskRequestV1::new(config, "test_task_id");
83        assert_eq!(request.task_id, "test_task_id");
84    }
85
86    #[test]
87    fn test_task_api_v1_delete_url() {
88        let endpoint = crate::common::api_endpoints::TaskApiV1::TaskDelete("task_123".to_string());
89        assert_eq!(endpoint.to_url(), "/open-apis/task/v1/tasks/task_123");
90    }
91}