openlark_workflow/v2/task/
remove_reminders.rs1use 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#[derive(Debug, Clone, Serialize, Default)]
17pub struct RemoveRemindersBody {
18 pub reminder_guids: Vec<String>,
20}
21
22#[derive(Debug, Clone, Deserialize)]
24pub struct RemoveRemindersResponse {
25 pub task_guid: String,
27 #[serde(default)]
29 pub removed_reminders: Vec<String>,
30}
31
32#[derive(Debug, Clone)]
34pub struct RemoveRemindersRequest {
35 config: Arc<Config>,
37 task_guid: String,
39 body: RemoveRemindersBody,
41}
42
43impl RemoveRemindersRequest {
44 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 pub fn reminder_guids(mut self, reminder_guids: Vec<String>) -> Self {
55 self.body.reminder_guids = reminder_guids;
56 self
57 }
58
59 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 pub async fn execute(self) -> SDKResult<RemoveRemindersResponse> {
67 self.execute_with_options(openlark_core::req_option::RequestOption::default())
68 .await
69 }
70
71 pub async fn execute_with_options(
73 self,
74 option: openlark_core::req_option::RequestOption,
75 ) -> SDKResult<RemoveRemindersResponse> {
76 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 let response =
87 openlark_core::http::Transport::request(request, &self.config, Some(option)).await?;
88 extract_response_data(response, "移除任务提醒")
89 }
90}
91
92impl ApiResponseTrait for RemoveRemindersResponse {
93 fn data_format() -> ResponseFormat {
94 ResponseFormat::Data
95 }
96}
97
98#[cfg(test)]
99#[allow(unused_imports)]
100mod tests {
101 use std::sync::Arc;
102
103 use super::*;
104
105 #[test]
106 fn test_remove_reminders_builder() {
107 let config = Arc::new(
108 openlark_core::config::Config::builder()
109 .app_id("test")
110 .app_secret("test")
111 .build(),
112 );
113
114 let request = RemoveRemindersRequest::new(config, "task_123")
115 .reminder_guids(vec!["reminder_1".to_string(), "reminder_2".to_string()]);
116
117 assert_eq!(request.task_guid, "task_123");
118 assert_eq!(
119 request.body.reminder_guids,
120 vec!["reminder_1", "reminder_2"]
121 );
122 }
123
124 #[test]
125 fn test_remove_reminder_single() {
126 let config = Arc::new(
127 openlark_core::config::Config::builder()
128 .app_id("test")
129 .app_secret("test")
130 .build(),
131 );
132
133 let request = RemoveRemindersRequest::new(config, "task_123")
134 .remove_reminder("reminder_1")
135 .remove_reminder("reminder_2");
136
137 assert_eq!(
138 request.body.reminder_guids,
139 vec!["reminder_1", "reminder_2"]
140 );
141 }
142
143 #[test]
144 fn test_task_remove_reminders_api_v2_url() {
145 let endpoint = TaskApiV2::TaskRemoveReminders("task_123".to_string());
146 assert_eq!(
147 endpoint.to_url(),
148 "/open-apis/task/v2/tasks/task_123/remove_reminders"
149 );
150 }
151}