Skip to main content

openlark_workflow/v1/task/reminder/
list.rs

1//! 获取任务提醒列表(v1)
2//!
3//! docPath: https://open.feishu.cn/document/server-docs/docs/task-v1/taskreminder/list
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 TaskReminderItemV1 {
17    /// 提醒 ID
18    pub reminder_id: String,
19    /// 提醒时间(Unix 时间戳)
20    pub trigger_time: i64,
21    /// 提醒类型
22    pub type_: Option<String>,
23}
24
25/// 获取任务提醒列表响应(v1)
26#[derive(Debug, Clone, Deserialize)]
27/// 任务提醒列表响应。
28pub struct ListTaskReminderResponseV1 {
29    /// 提醒列表
30    pub items: Vec<TaskReminderItemV1>,
31}
32
33/// 获取任务提醒列表请求(v1)
34#[derive(Debug, Clone)]
35/// 获取任务提醒列表请求构建器。
36pub struct ListTaskReminderRequestV1 {
37    config: Arc<Config>,
38    task_id: String,
39}
40
41impl ListTaskReminderRequestV1 {
42    /// 创建新的请求构建器。
43    pub fn new(config: Arc<Config>, task_id: impl Into<String>) -> Self {
44        Self {
45            config,
46            task_id: task_id.into(),
47        }
48    }
49
50    /// 执行请求
51    pub async fn execute(self) -> SDKResult<ListTaskReminderResponseV1> {
52        self.execute_with_options(openlark_core::req_option::RequestOption::default())
53            .await
54    }
55
56    /// 执行请求(带选项)
57    pub async fn execute_with_options(
58        self,
59        option: openlark_core::req_option::RequestOption,
60    ) -> SDKResult<ListTaskReminderResponseV1> {
61        let api_endpoint =
62            crate::common::api_endpoints::TaskApiV1::TaskReminderList(self.task_id.clone());
63        let request = ApiRequest::<ListTaskReminderResponseV1>::get(api_endpoint.to_url());
64
65        let response =
66            openlark_core::http::Transport::request(request, &self.config, Some(option)).await?;
67        response.data.ok_or_else(|| {
68            openlark_core::error::validation_error("响应数据为空", "服务器没有返回有效的数据")
69        })
70    }
71}
72
73impl ApiResponseTrait for ListTaskReminderResponseV1 {
74    fn data_format() -> ResponseFormat {
75        ResponseFormat::Data
76    }
77}
78
79#[cfg(test)]
80#[allow(unused_imports)]
81mod tests {
82
83    #[test]
84    fn test_list_task_reminder_v1_url() {
85        let endpoint =
86            crate::common::api_endpoints::TaskApiV1::TaskReminderList("task_123".to_string());
87        assert_eq!(
88            endpoint.to_url(),
89            "/open-apis/task/v1/tasks/task_123/reminders"
90        );
91    }
92}