use crate::common::{api_endpoints::TaskApiV2, api_utils::*};
use crate::v2::task::models::DeleteTaskResponse;
use openlark_core::{
SDKResult,
api::{ApiRequest, ApiResponseTrait, ResponseFormat},
config::Config,
validate_required,
};
use std::sync::Arc;
#[derive(Debug, Clone)]
pub struct DeleteTaskRequest {
config: Arc<Config>,
task_guid: String,
}
impl DeleteTaskRequest {
pub fn new(config: Arc<Config>, task_guid: String) -> Self {
Self { config, task_guid }
}
pub async fn execute(self) -> SDKResult<DeleteTaskResponse> {
self.execute_with_options(openlark_core::req_option::RequestOption::default())
.await
}
pub async fn execute_with_options(
self,
option: openlark_core::req_option::RequestOption,
) -> SDKResult<DeleteTaskResponse> {
validate_required!(self.task_guid.trim(), "任务GUID不能为空");
let api_endpoint = TaskApiV2::TaskDelete(self.task_guid.clone());
let request = ApiRequest::<DeleteTaskResponse>::delete(api_endpoint.to_url());
let response =
openlark_core::http::Transport::request(request, &self.config, Some(option)).await?;
extract_response_data(response, "删除任务")
}
}
impl ApiResponseTrait for DeleteTaskResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
#[cfg(test)]
#[allow(unused_imports)]
mod tests {
use std::sync::Arc;
use super::*;
#[test]
fn test_delete_task_request() {
let config = openlark_core::config::Config::builder()
.app_id("test")
.app_secret("test")
.build();
let request = DeleteTaskRequest::new(Arc::new(config), "task_123".to_string());
assert_eq!(request.task_guid, "task_123");
}
}