Skip to main content

openlark_workflow/v1/task/follower/
delete.rs

1//! 删除任务关注者(v1)
2//!
3//! docPath: https://open.feishu.cn/document/server-docs/docs/task-v1/taskfollower/delete
4
5use openlark_core::{
6    SDKResult,
7    api::{ApiRequest, ApiResponseTrait, ResponseFormat},
8    config::Config,
9};
10use serde::Deserialize;
11use std::sync::Arc;
12
13/// 删除任务关注者响应(v1)
14#[derive(Debug, Clone, Deserialize)]
15/// 删除任务关注者响应。
16pub struct DeleteTaskFollowerResponseV1 {
17    /// 是否成功删除
18    pub success: bool,
19}
20
21/// 删除任务关注者请求(v1)
22#[derive(Debug, Clone)]
23/// 删除任务关注者请求构建器。
24pub struct DeleteTaskFollowerRequestV1 {
25    config: Arc<Config>,
26    task_id: String,
27    follower_id: String,
28}
29
30impl DeleteTaskFollowerRequestV1 {
31    /// 创建新的请求构建器。
32    pub fn new(
33        config: Arc<Config>,
34        task_id: impl Into<String>,
35        follower_id: impl Into<String>,
36    ) -> Self {
37        Self {
38            config,
39            task_id: task_id.into(),
40            follower_id: follower_id.into(),
41        }
42    }
43
44    /// 执行请求
45    pub async fn execute(self) -> SDKResult<DeleteTaskFollowerResponseV1> {
46        self.execute_with_options(openlark_core::req_option::RequestOption::default())
47            .await
48    }
49
50    /// 执行请求(带选项)
51    pub async fn execute_with_options(
52        self,
53        option: openlark_core::req_option::RequestOption,
54    ) -> SDKResult<DeleteTaskFollowerResponseV1> {
55        let api_endpoint = crate::common::api_endpoints::TaskApiV1::TaskFollowerDelete(
56            self.task_id.clone(),
57            self.follower_id.clone(),
58        );
59        let request = ApiRequest::<DeleteTaskFollowerResponseV1>::delete(api_endpoint.to_url());
60
61        let response =
62            openlark_core::http::Transport::request(request, &self.config, Some(option)).await?;
63        response.data.ok_or_else(|| {
64            openlark_core::error::validation_error("响应数据为空", "服务器没有返回有效的数据")
65        })
66    }
67}
68
69impl ApiResponseTrait for DeleteTaskFollowerResponseV1 {
70    fn data_format() -> ResponseFormat {
71        ResponseFormat::Data
72    }
73}
74
75#[cfg(test)]
76#[allow(unused_imports)]
77mod tests {
78
79    #[test]
80    fn test_delete_task_follower_v1_url() {
81        let endpoint = crate::common::api_endpoints::TaskApiV1::TaskFollowerDelete(
82            "task_123".to_string(),
83            "user_456".to_string(),
84        );
85        assert_eq!(
86            endpoint.to_url(),
87            "/open-apis/task/v1/tasks/task_123/followers/user_456"
88        );
89    }
90}