Skip to main content

openlark_workflow/v2/task/
remove_reminders.rs

1//! 移除任务提醒
2//!
3//! docPath: https://open.feishu.cn/document/server-docs/docs/task-v2/task-remove_reminders/create
4
5use crate::common::{api_endpoints::TaskApiV2, api_utils::*};
6use openlark_core::{
7    api::{ApiRequest, ApiResponseTrait, ResponseFormat},
8    config::Config,
9    validate_required, SDKResult,
10};
11use serde::{Deserialize, Serialize};
12use std::sync::Arc;
13
14/// 移除任务提醒请求体
15#[derive(Debug, Clone, Serialize, Default)]
16pub struct RemoveRemindersBody {
17    /// 提醒 GUID 列表
18    pub reminder_guids: Vec<String>,
19}
20
21/// 移除任务提醒响应
22#[derive(Debug, Clone, Deserialize)]
23pub struct RemoveRemindersResponse {
24    /// 任务 GUID
25    pub task_guid: String,
26    /// 移除的提醒 GUID 列表
27    #[serde(default)]
28    pub removed_reminders: Vec<String>,
29}
30
31/// 移除任务提醒请求
32#[derive(Debug, Clone)]
33pub struct RemoveRemindersRequest {
34    /// 配置信息
35    config: Arc<Config>,
36    /// 任务 GUID
37    task_guid: String,
38    /// 请求体
39    body: RemoveRemindersBody,
40}
41
42impl RemoveRemindersRequest {
43    pub fn new(config: Arc<Config>, task_guid: impl Into<String>) -> Self {
44        Self {
45            config,
46            task_guid: task_guid.into(),
47            body: RemoveRemindersBody::default(),
48        }
49    }
50
51    /// 设置提醒 GUID 列表
52    pub fn reminder_guids(mut self, reminder_guids: Vec<String>) -> Self {
53        self.body.reminder_guids = reminder_guids;
54        self
55    }
56
57    /// 移除单个提醒
58    pub fn remove_reminder(mut self, reminder_guid: impl Into<String>) -> Self {
59        self.body.reminder_guids.push(reminder_guid.into());
60        self
61    }
62
63    /// 执行请求
64    pub async fn execute(self) -> SDKResult<RemoveRemindersResponse> {
65        self.execute_with_options(openlark_core::req_option::RequestOption::default())
66            .await
67    }
68
69    /// 执行请求(带选项)
70    pub async fn execute_with_options(
71        self,
72        option: openlark_core::req_option::RequestOption,
73    ) -> SDKResult<RemoveRemindersResponse> {
74        // 验证必填字段
75        validate_required!(self.task_guid.trim(), "任务GUID不能为空");
76        validate_required!(self.body.reminder_guids, "提醒GUID列表不能为空");
77
78        let api_endpoint = TaskApiV2::TaskRemoveReminders(self.task_guid.clone());
79        let mut request = ApiRequest::<RemoveRemindersResponse>::post(api_endpoint.to_url());
80
81        let request_body = &self.body;
82        request = request.body(serialize_params(request_body, "移除任务提醒")?);
83
84        let response =
85            openlark_core::http::Transport::request(request, &self.config, Some(option)).await?;
86        extract_response_data(response, "移除任务提醒")
87    }
88}
89
90impl ApiResponseTrait for RemoveRemindersResponse {
91    fn data_format() -> ResponseFormat {
92        ResponseFormat::Data
93    }
94}
95
96#[cfg(test)]
97#[allow(unused_imports)]
98mod tests {
99    use std::sync::Arc;
100
101    use super::*;
102
103    #[test]
104    fn test_remove_reminders_builder() {
105        let config = Arc::new(
106            openlark_core::config::Config::builder()
107                .app_id("test")
108                .app_secret("test")
109                .build(),
110        );
111
112        let request = RemoveRemindersRequest::new(config, "task_123")
113            .reminder_guids(vec!["reminder_1".to_string(), "reminder_2".to_string()]);
114
115        assert_eq!(request.task_guid, "task_123");
116        assert_eq!(
117            request.body.reminder_guids,
118            vec!["reminder_1", "reminder_2"]
119        );
120    }
121
122    #[test]
123    fn test_remove_reminder_single() {
124        let config = Arc::new(
125            openlark_core::config::Config::builder()
126                .app_id("test")
127                .app_secret("test")
128                .build(),
129        );
130
131        let request = RemoveRemindersRequest::new(config, "task_123")
132            .remove_reminder("reminder_1")
133            .remove_reminder("reminder_2");
134
135        assert_eq!(
136            request.body.reminder_guids,
137            vec!["reminder_1", "reminder_2"]
138        );
139    }
140
141    #[test]
142    fn test_task_remove_reminders_api_v2_url() {
143        let endpoint = TaskApiV2::TaskRemoveReminders("task_123".to_string());
144        assert_eq!(
145            endpoint.to_url(),
146            "/open-apis/task/v2/tasks/task_123/remove_reminders"
147        );
148    }
149}