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