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 openlark_core::http::Transport::request_typed(
84 request,
85 &self.config,
86 Some(option),
87 "响应数据为空",
88 )
89 .await
90 }
91}
92
93impl ApiResponseTrait for BatchDeleteTaskFollowerResponseV1 {
94 fn data_format() -> ResponseFormat {
95 ResponseFormat::Data
96 }
97}
98
99#[cfg(test)]
100#[allow(unused_imports)]
101mod tests {
102 use std::sync::Arc;
103
104 use super::*;
105
106 #[test]
107 fn test_batch_delete_task_follower_v1_builder() {
108 let config = Arc::new(
109 openlark_core::config::Config::builder()
110 .app_id("test")
111 .app_secret("test")
112 .build(),
113 );
114
115 let request = BatchDeleteTaskFollowerRequestV1::new(config.clone(), "task_123")
116 .follower_ids(vec!["user_1", "user_2"]);
117
118 assert_eq!(request.body.follower_ids.len(), 2);
119 assert_eq!(request.task_id, "task_123");
120 }
121
122 #[test]
123 fn test_task_follower_batch_delete_v1_url() {
124 let endpoint = crate::common::api_endpoints::TaskApiV1::TaskFollowerBatchDelete(
125 "task_123".to_string(),
126 );
127 assert_eq!(
128 endpoint.to_url(),
129 "/open-apis/task/v1/tasks/task_123/batch_delete_follower"
130 );
131 }
132}