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        openlark_core::http::Transport::request_typed(
53            request,
54            &self.config,
55            Some(option),
56            "响应数据为空",
57        )
58        .await
59    }
60}
61
62impl ApiResponseTrait for DeleteTaskResponseV1 {
63    fn data_format() -> ResponseFormat {
64        ResponseFormat::Data
65    }
66}
67
68#[cfg(test)]
69#[allow(unused_imports)]
70mod tests {
71    use std::sync::Arc;
72
73    use super::*;
74
75    #[test]
76    fn test_delete_task_v1_builder() {
77        let config = Arc::new(
78            openlark_core::config::Config::builder()
79                .app_id("test")
80                .app_secret("test")
81                .build(),
82        );
83
84        let request = DeleteTaskRequestV1::new(config, "test_task_id");
85        assert_eq!(request.task_id, "test_task_id");
86    }
87
88    #[test]
89    fn test_task_api_v1_delete_url() {
90        let endpoint = crate::common::api_endpoints::TaskApiV1::TaskDelete("task_123".to_string());
91        assert_eq!(endpoint.to_url(), "/open-apis/task/v1/tasks/task_123");
92    }
93}