openlark_workflow/v1/task/
uncomplete.rs1use openlark_core::{
6 SDKResult,
7 api::{ApiRequest, ApiResponseTrait, ResponseFormat},
8 config::Config,
9};
10use serde::Deserialize;
11use std::sync::Arc;
12
13#[derive(Debug, Clone, Deserialize)]
15pub struct UncompleteTaskResponseV1 {
17 pub id: String,
19 pub summary: String,
21 pub is_completed: bool,
23}
24
25#[derive(Debug, Clone)]
27pub struct UncompleteTaskRequestV1 {
29 config: Arc<Config>,
30 task_id: String,
31}
32
33impl UncompleteTaskRequestV1 {
34 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 pub async fn execute(self) -> SDKResult<UncompleteTaskResponseV1> {
44 self.execute_with_options(openlark_core::req_option::RequestOption::default())
45 .await
46 }
47
48 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 let response =
57 openlark_core::http::Transport::request(request, &self.config, Some(option)).await?;
58 response.data.ok_or_else(|| {
59 openlark_core::error::validation_error("响应数据为空", "服务器没有返回有效的数据")
60 })
61 }
62}
63
64impl ApiResponseTrait for UncompleteTaskResponseV1 {
65 fn data_format() -> ResponseFormat {
66 ResponseFormat::Data
67 }
68}
69
70#[cfg(test)]
71#[allow(unused_imports)]
72mod tests {
73 use std::sync::Arc;
74
75 use super::*;
76
77 #[test]
78 fn test_uncomplete_task_v1_builder() {
79 let config = Arc::new(
80 openlark_core::config::Config::builder()
81 .app_id("test")
82 .app_secret("test")
83 .build(),
84 );
85
86 let request = UncompleteTaskRequestV1::new(config, "test_task_id");
87 assert_eq!(request.task_id, "test_task_id");
88 }
89
90 #[test]
91 fn test_task_api_v1_uncomplete_url() {
92 let endpoint =
93 crate::common::api_endpoints::TaskApiV1::TaskUncomplete("task_123".to_string());
94 assert_eq!(
95 endpoint.to_url(),
96 "/open-apis/task/v1/tasks/task_123/uncomplete"
97 );
98 }
99}