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