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