use crate::common::api_endpoints::TaskApiV2;
use crate::v2::section::models::DeleteSectionResponse;
use openlark_core::{
SDKResult,
api::{ApiRequest, ApiResponseTrait, ResponseFormat},
config::Config,
validate_required,
};
use std::sync::Arc;
#[derive(Debug, Clone)]
pub struct DeleteSectionRequest {
config: Arc<Config>,
section_guid: String,
}
impl DeleteSectionRequest {
pub fn new(config: Arc<Config>, section_guid: String) -> Self {
Self {
config,
section_guid,
}
}
pub async fn execute(self) -> SDKResult<DeleteSectionResponse> {
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<DeleteSectionResponse> {
validate_required!(self.section_guid.trim(), "分组GUID不能为空");
let api_endpoint = TaskApiV2::SectionDelete(self.section_guid.clone());
let request = ApiRequest::<DeleteSectionResponse>::delete(api_endpoint.to_url());
openlark_core::http::Transport::request_typed(
request,
&self.config,
Some(option),
"删除分组",
)
.await
}
}
impl ApiResponseTrait for DeleteSectionResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
#[cfg(test)]
#[allow(unused_imports)]
mod tests {
use std::sync::Arc;
use super::*;
#[test]
fn test_delete_section_request() {
let config = openlark_core::config::Config::builder()
.app_id("test")
.app_secret("test")
.build();
let request = DeleteSectionRequest::new(Arc::new(config), "section_456".to_string());
assert_eq!(request.section_guid, "section_456");
}
}