Skip to main content

openlark_workflow/v1/task/
get.rs

1//! 获取指定任务(v1)
2//!
3//! docPath: <https://open.feishu.cn/document/server-docs/docs/task-v1/task/get>
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 TaskV1 {
17    /// 任务 ID
18    pub id: String,
19    /// 任务标题
20    pub summary: String,
21    /// 任务描述
22    #[serde(default)]
23    /// 任务描述。
24    pub description: Option<String>,
25    /// 任务开始时间
26    #[serde(default)]
27    /// 任务开始时间。
28    pub start: Option<String>,
29    /// 任务截止时间
30    #[serde(default)]
31    /// 任务截止时间。
32    pub due: Option<String>,
33    /// 任务优先级(1-5)
34    #[serde(default)]
35    /// 任务优先级。
36    pub priority: Option<i32>,
37    /// 任务是否完成
38    pub is_completed: bool,
39    /// 创建时间
40    pub created_at: String,
41    /// 更新时间
42    pub updated_at: String,
43}
44
45/// 获取任务响应(v1)
46#[derive(Debug, Clone, Deserialize)]
47/// 获取任务响应。
48pub struct GetTaskResponseV1 {
49    /// 任务信息
50    pub task: TaskV1,
51}
52
53/// 获取任务请求(v1)
54#[derive(Debug, Clone)]
55/// 获取任务请求构建器。
56pub struct GetTaskRequestV1 {
57    config: Arc<Config>,
58    task_id: String,
59}
60
61impl GetTaskRequestV1 {
62    /// 创建新的请求构建器。
63    pub fn new(config: Arc<Config>, task_id: impl Into<String>) -> Self {
64        Self {
65            config,
66            task_id: task_id.into(),
67        }
68    }
69
70    /// 执行请求
71    pub async fn execute(self) -> SDKResult<GetTaskResponseV1> {
72        self.execute_with_options(openlark_core::req_option::RequestOption::default())
73            .await
74    }
75
76    /// 执行请求(带选项)
77    pub async fn execute_with_options(
78        self,
79        option: openlark_core::req_option::RequestOption,
80    ) -> SDKResult<GetTaskResponseV1> {
81        let api_endpoint = crate::common::api_endpoints::TaskApiV1::TaskGet(self.task_id);
82        let request = ApiRequest::<GetTaskResponseV1>::get(api_endpoint.to_url());
83
84        openlark_core::http::Transport::request_typed(
85            request,
86            &self.config,
87            Some(option),
88            "响应数据为空",
89        )
90        .await
91    }
92}
93
94impl ApiResponseTrait for GetTaskResponseV1 {
95    fn data_format() -> ResponseFormat {
96        ResponseFormat::Data
97    }
98}
99
100#[cfg(test)]
101#[allow(unused_imports)]
102mod tests {
103    use std::sync::Arc;
104
105    use super::*;
106
107    #[test]
108    fn test_get_task_v1_builder() {
109        let config = Arc::new(
110            openlark_core::config::Config::builder()
111                .app_id("test")
112                .app_secret("test")
113                .build(),
114        );
115
116        let request = GetTaskRequestV1::new(config, "test_task_id");
117        assert_eq!(request.task_id, "test_task_id");
118    }
119
120    #[test]
121    fn test_task_api_v1_get_url() {
122        let endpoint = crate::common::api_endpoints::TaskApiV1::TaskGet("task_123".to_string());
123        assert_eq!(endpoint.to_url(), "/open-apis/task/v1/tasks/task_123");
124    }
125}