openlark_workflow/v1/task/
uncomplete.rs1use openlark_core::{
6 api::{ApiRequest, ApiResponseTrait, ResponseFormat},
7 config::Config,
8 SDKResult,
9};
10use serde::Deserialize;
11use std::sync::Arc;
12
13#[derive(Debug, Clone, Deserialize)]
15pub struct UncompleteTaskResponseV1 {
16 pub id: String,
18 pub summary: String,
20 pub is_completed: bool,
22}
23
24#[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 pub async fn execute(self) -> SDKResult<UncompleteTaskResponseV1> {
41 self.execute_with_options(openlark_core::req_option::RequestOption::default())
42 .await
43 }
44
45 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}