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