openlark_workflow/v2/tasklist/
get.rs1use crate::common::api_endpoints::TaskApiV2;
6use crate::v2::tasklist::models::GetTasklistResponse;
7use openlark_core::{
8 SDKResult,
9 api::{ApiRequest, ApiResponseTrait, ResponseFormat},
10 config::Config,
11 validate_required,
12};
13use std::sync::Arc;
14
15#[derive(Debug, Clone)]
17pub struct GetTasklistRequest {
18 config: Arc<Config>,
20 tasklist_guid: String,
22}
23
24impl GetTasklistRequest {
25 pub fn new(config: Arc<Config>, tasklist_guid: String) -> Self {
27 Self {
28 config,
29 tasklist_guid,
30 }
31 }
32
33 pub async fn execute(self) -> SDKResult<GetTasklistResponse> {
35 self.execute_with_options(openlark_core::req_option::RequestOption::default())
36 .await
37 }
38
39 pub async fn execute_with_options(
41 self,
42 option: openlark_core::req_option::RequestOption,
43 ) -> SDKResult<GetTasklistResponse> {
44 validate_required!(self.tasklist_guid.trim(), "任务清单GUID不能为空");
46
47 let api_endpoint = TaskApiV2::TasklistGet(self.tasklist_guid.clone());
48 let request = ApiRequest::<GetTasklistResponse>::get(api_endpoint.to_url());
49
50 openlark_core::http::Transport::request_typed(
51 request,
52 &self.config,
53 Some(option),
54 "获取任务清单",
55 )
56 .await
57 }
58}
59
60impl ApiResponseTrait for GetTasklistResponse {
61 fn data_format() -> ResponseFormat {
62 ResponseFormat::Data
63 }
64}
65
66#[cfg(test)]
67#[allow(unused_imports)]
68mod tests {
69 use std::sync::Arc;
70
71 use super::*;
72
73 #[test]
74 fn test_get_tasklist_request() {
75 let config = openlark_core::config::Config::builder()
76 .app_id("test")
77 .app_secret("test")
78 .build();
79
80 let request = GetTasklistRequest::new(Arc::new(config), "tasklist_123".to_string());
81
82 assert_eq!(request.tasklist_guid, "tasklist_123");
83 }
84}