Skip to main content

openlark_workflow/v1/task/
uncomplete.rs

1//! 取消完成任务(v1)
2//!
3//! docPath: <https://open.feishu.cn/document/server-docs/docs/task-v1/task/uncomplete>
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 UncompleteTaskResponseV1 {
17    /// 任务 ID
18    pub id: String,
19    /// 任务标题
20    pub summary: String,
21    /// 任务是否完成
22    pub is_completed: bool,
23}
24
25/// 取消完成任务请求(v1)
26#[derive(Debug, Clone)]
27/// 取消完成任务请求构建器。
28pub struct UncompleteTaskRequestV1 {
29    config: Arc<Config>,
30    task_id: String,
31}
32
33impl UncompleteTaskRequestV1 {
34    /// 创建新的请求构建器。
35    pub fn new(config: Arc<Config>, task_id: impl Into<String>) -> Self {
36        Self {
37            config,
38            task_id: task_id.into(),
39        }
40    }
41
42    /// 执行请求
43    pub async fn execute(self) -> SDKResult<UncompleteTaskResponseV1> {
44        self.execute_with_options(openlark_core::req_option::RequestOption::default())
45            .await
46    }
47
48    /// 执行请求(带选项)
49    pub async fn execute_with_options(
50        self,
51        option: openlark_core::req_option::RequestOption,
52    ) -> SDKResult<UncompleteTaskResponseV1> {
53        let api_endpoint = crate::common::api_endpoints::TaskApiV1::TaskUncomplete(self.task_id);
54        let request = ApiRequest::<UncompleteTaskResponseV1>::post(api_endpoint.to_url());
55
56        openlark_core::http::Transport::request_typed(
57            request,
58            &self.config,
59            Some(option),
60            "响应数据为空",
61        )
62        .await
63    }
64}
65
66impl ApiResponseTrait for UncompleteTaskResponseV1 {
67    fn data_format() -> ResponseFormat {
68        ResponseFormat::Data
69    }
70}
71
72#[cfg(test)]
73#[allow(unused_imports)]
74mod tests {
75    use std::sync::Arc;
76
77    use super::*;
78
79    #[test]
80    fn test_uncomplete_task_v1_builder() {
81        let config = Arc::new(
82            openlark_core::config::Config::builder()
83                .app_id("test")
84                .app_secret("test")
85                .build(),
86        );
87
88        let request = UncompleteTaskRequestV1::new(config, "test_task_id");
89        assert_eq!(request.task_id, "test_task_id");
90    }
91
92    #[test]
93    fn test_task_api_v1_uncomplete_url() {
94        let endpoint =
95            crate::common::api_endpoints::TaskApiV1::TaskUncomplete("task_123".to_string());
96        assert_eq!(
97            endpoint.to_url(),
98            "/open-apis/task/v1/tasks/task_123/uncomplete"
99        );
100    }
101}