openlark_workflow/v1/task/follower/
batch_delete.rs1use openlark_core::{
6 SDKResult,
7 api::{ApiRequest, ApiResponseTrait, ResponseFormat},
8 config::Config,
9};
10use serde::{Deserialize, Serialize};
11use std::sync::Arc;
12
13#[derive(Debug, Clone, Serialize, Default)]
15pub struct BatchDeleteTaskFollowerBodyV1 {
17 pub follower_ids: Vec<String>,
19}
20
21#[derive(Debug, Clone, Deserialize)]
23pub struct BatchDeleteTaskFollowerResponseV1 {
25 pub failed_follower_ids: Option<Vec<String>>,
27}
28
29#[derive(Debug, Clone)]
31pub struct BatchDeleteTaskFollowerRequestV1 {
33 config: Arc<Config>,
34 task_id: String,
35 body: BatchDeleteTaskFollowerBodyV1,
36}
37
38impl BatchDeleteTaskFollowerRequestV1 {
39 pub fn new(config: Arc<Config>, task_id: impl Into<String>) -> Self {
41 Self {
42 config,
43 task_id: task_id.into(),
44 body: BatchDeleteTaskFollowerBodyV1::default(),
45 }
46 }
47
48 pub fn follower_ids(mut self, follower_ids: Vec<impl Into<String>>) -> Self {
50 self.body.follower_ids = follower_ids.into_iter().map(|v| v.into()).collect();
51 self
52 }
53
54 pub async fn execute(self) -> SDKResult<BatchDeleteTaskFollowerResponseV1> {
56 self.execute_with_options(openlark_core::req_option::RequestOption::default())
57 .await
58 }
59
60 pub async fn execute_with_options(
62 self,
63 option: openlark_core::req_option::RequestOption,
64 ) -> SDKResult<BatchDeleteTaskFollowerResponseV1> {
65 if self.body.follower_ids.is_empty() {
66 return Err(openlark_core::error::validation_error(
67 "关注者用户 ID 列表不能为空",
68 "",
69 ));
70 }
71
72 let api_endpoint =
73 crate::common::api_endpoints::TaskApiV1::TaskFollowerBatchDelete(self.task_id.clone());
74 let mut request =
75 ApiRequest::<BatchDeleteTaskFollowerResponseV1>::post(api_endpoint.to_url());
76
77 let body_json = serde_json::to_value(&self.body).map_err(|e| {
78 openlark_core::error::validation_error("序列化请求体失败", e.to_string().as_str())
79 })?;
80
81 request = request.body(body_json);
82
83 let response =
84 openlark_core::http::Transport::request(request, &self.config, Some(option)).await?;
85 response.data.ok_or_else(|| {
86 openlark_core::error::validation_error("响应数据为空", "服务器没有返回有效的数据")
87 })
88 }
89}
90
91impl ApiResponseTrait for BatchDeleteTaskFollowerResponseV1 {
92 fn data_format() -> ResponseFormat {
93 ResponseFormat::Data
94 }
95}
96
97#[cfg(test)]
98#[allow(unused_imports)]
99mod tests {
100 use std::sync::Arc;
101
102 use super::*;
103
104 #[test]
105 fn test_batch_delete_task_follower_v1_builder() {
106 let config = Arc::new(
107 openlark_core::config::Config::builder()
108 .app_id("test")
109 .app_secret("test")
110 .build(),
111 );
112
113 let request = BatchDeleteTaskFollowerRequestV1::new(config.clone(), "task_123")
114 .follower_ids(vec!["user_1", "user_2"]);
115
116 assert_eq!(request.body.follower_ids.len(), 2);
117 assert_eq!(request.task_id, "task_123");
118 }
119
120 #[test]
121 fn test_task_follower_batch_delete_v1_url() {
122 let endpoint = crate::common::api_endpoints::TaskApiV1::TaskFollowerBatchDelete(
123 "task_123".to_string(),
124 );
125 assert_eq!(
126 endpoint.to_url(),
127 "/open-apis/task/v1/tasks/task_123/batch_delete_follower"
128 );
129 }
130}