openlark_workflow/v2/task/
delete.rs1use crate::common::{api_endpoints::TaskApiV2, api_utils::*};
6use crate::v2::task::models::DeleteTaskResponse;
7use openlark_core::{
8 api::{ApiRequest, ApiResponseTrait, ResponseFormat},
9 config::Config,
10 validate_required, SDKResult,
11};
12use std::sync::Arc;
13
14#[derive(Debug, Clone)]
16pub struct DeleteTaskRequest {
17 config: Arc<Config>,
19 task_guid: String,
21}
22
23impl DeleteTaskRequest {
24 pub fn new(config: Arc<Config>, task_guid: String) -> Self {
25 Self { config, task_guid }
26 }
27
28 pub async fn execute(self) -> SDKResult<DeleteTaskResponse> {
30 self.execute_with_options(openlark_core::req_option::RequestOption::default())
31 .await
32 }
33
34 pub async fn execute_with_options(
36 self,
37 option: openlark_core::req_option::RequestOption,
38 ) -> SDKResult<DeleteTaskResponse> {
39 validate_required!(self.task_guid.trim(), "任务GUID不能为空");
41
42 let api_endpoint = TaskApiV2::TaskDelete(self.task_guid.clone());
43 let request = ApiRequest::<DeleteTaskResponse>::delete(api_endpoint.to_url());
44
45 let response =
46 openlark_core::http::Transport::request(request, &self.config, Some(option)).await?;
47 extract_response_data(response, "删除任务")
48 }
49}
50
51impl ApiResponseTrait for DeleteTaskResponse {
52 fn data_format() -> ResponseFormat {
53 ResponseFormat::Data
54 }
55}
56
57#[cfg(test)]
58#[allow(unused_imports)]
59mod tests {
60 use std::sync::Arc;
61
62 use super::*;
63
64 #[test]
65 fn test_delete_task_request() {
66 let config = openlark_core::config::Config::builder()
67 .app_id("test")
68 .app_secret("test")
69 .build();
70
71 let request = DeleteTaskRequest::new(Arc::new(config), "task_123".to_string());
72
73 assert_eq!(request.task_guid, "task_123");
74 }
75}