openlark_workflow/v2/section/
delete.rs1use crate::common::{api_endpoints::TaskApiV2, api_utils::*};
6use crate::v2::section::models::DeleteSectionResponse;
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 DeleteSectionRequest {
17 config: Arc<Config>,
19 tasklist_guid: String,
21 section_guid: String,
23}
24
25impl DeleteSectionRequest {
26 pub fn new(config: Arc<Config>, tasklist_guid: String, section_guid: String) -> Self {
27 Self {
28 config,
29 tasklist_guid,
30 section_guid,
31 }
32 }
33
34 pub async fn execute(self) -> SDKResult<DeleteSectionResponse> {
36 self.execute_with_options(openlark_core::req_option::RequestOption::default())
37 .await
38 }
39
40 pub async fn execute_with_options(
42 self,
43 option: openlark_core::req_option::RequestOption,
44 ) -> SDKResult<DeleteSectionResponse> {
45 validate_required!(self.tasklist_guid.trim(), "任务清单GUID不能为空");
47 validate_required!(self.section_guid.trim(), "分组GUID不能为空");
48
49 let api_endpoint =
50 TaskApiV2::SectionDelete(self.tasklist_guid.clone(), self.section_guid.clone());
51 let request = ApiRequest::<DeleteSectionResponse>::delete(api_endpoint.to_url());
52
53 let response =
54 openlark_core::http::Transport::request(request, &self.config, Some(option)).await?;
55 extract_response_data(response, "删除分组")
56 }
57}
58
59impl ApiResponseTrait for DeleteSectionResponse {
60 fn data_format() -> ResponseFormat {
61 ResponseFormat::Data
62 }
63}
64
65#[cfg(test)]
66#[allow(unused_imports)]
67mod tests {
68 use std::sync::Arc;
69
70 use super::*;
71
72 #[test]
73 fn test_delete_section_request() {
74 let config = openlark_core::config::Config::builder()
75 .app_id("test")
76 .app_secret("test")
77 .build();
78
79 let request = DeleteSectionRequest::new(
80 Arc::new(config),
81 "tasklist_123".to_string(),
82 "section_456".to_string(),
83 );
84
85 assert_eq!(request.tasklist_guid, "tasklist_123");
86 assert_eq!(request.section_guid, "section_456");
87 }
88}