meegle/subtask/
api.rs

1use super::types::*;
2use crate::client::{AuthType, Client};
3use crate::error::ApiResult;
4
5pub trait SubTaskApi {
6    /// 创建子任务
7    /// 该接口用于在一个工作项实例的指定节点上创建一个子任务,对应平台的功能可参考新增任务。
8    /// 对应的权限申请在权限管理-子任务分类下,相关功能介绍详见权限管理。
9    fn create_subtask(
10        &self,
11        project_key: &str,
12        work_item_type_key: &str,
13        work_item_id: i64,
14        request: CreateSubTaskRequest,
15        auth: AuthType,
16    ) -> impl std::future::Future<Output = ApiResult<i64>> + Send;
17
18    /// 更新子任务
19    /// 该接口用于更新工作项实例指定节点上的一个子任务详细信息,对应平台的功能,
20    /// 如实例侧操作可参考任务管理,如流程节点上默认的子任务配置可参考完成任务。
21    fn update_subtask(
22        &self,
23        project_key: &str,
24        work_item_type_key: &str,
25        work_item_id: i64,
26        node_id: &str,
27        task_id: i64,
28        request: UpdateSubTaskRequest,
29        auth: AuthType,
30    ) -> impl std::future::Future<Output = ApiResult<()>> + Send;
31
32    /// 删除子任务
33    /// 该接口用于删除指定工作项实例中的一个子任务,对应平台的功能可参考任务管理。
34    /// 对应的权限申请在权限管理-子任务分类下,相关功能介绍详见权限管理。
35    fn delete_subtask(
36        &self,
37        project_key: &str,
38        work_item_type_key: &str,
39        work_item_id: i64,
40        task_id: i64,
41        auth: AuthType,
42    ) -> impl std::future::Future<Output = ApiResult<()>> + Send;
43
44    /// 子任务完成/回滚
45    /// 该接口用于完成或者回滚工作项实例指定节点上的一个子任务,对应平台的功能,
46    /// 如实例侧操作可参考任务管理,如流程节点上默认的子任务配置可参考完成任务。
47    /// 对应的权限申请在权限管理-子任务分类下,相关功能介绍详见权限管理。
48    fn modify_subtask(
49        &self,
50        project_key: &str,
51        work_item_type_key: &str,
52        work_item_id: i64,
53        request: ModifySubTaskRequest,
54        auth: AuthType,
55    ) -> impl std::future::Future<Output = ApiResult<()>> + Send;
56
57    /// 获取指定工作项实例上的子任务详细信息
58    /// 该接口用于获取指定工作项实例上的子任务详细信息,对应平台的功能,
59    /// 如实例侧操作可参考任务管理,如流程节点上默认的子任务配置可参考完成任务。
60    /// 对应的权限申请在权限管理-子任务分类下,相关功能介绍详见权限管理。
61    fn get_subtasks(
62        &self,
63        project_key: &str,
64        work_item_type_key: &str,
65        work_item_id: i64,
66        node_id: Option<&str>,
67        auth: AuthType,
68    ) -> impl std::future::Future<Output = ApiResult<GetSubTaskResponse>> + Send;
69
70    /// 获取指定的子任务列表(跨空间)
71    /// 该接口用于跨空间搜索符合传入条件的子任务,对应平台的功能,
72    /// 如实例侧操作可参考任务管理,如流程节点上默认的子任务配置可参考完成任务。
73    /// 对应的权限申请在权限管理-子任务分类下,相关功能介绍详见权限管理。
74    fn search_subtasks(
75        &self,
76        request: SearchSubTaskRequest,
77        auth: AuthType,
78    ) -> impl std::future::Future<Output = ApiResult<SearchSubTaskResponse>> + Send;
79}
80
81impl SubTaskApi for Client {
82    async fn create_subtask(
83        &self,
84        project_key: &str,
85        work_item_type_key: &str,
86        work_item_id: i64,
87        request: CreateSubTaskRequest,
88        auth: AuthType,
89    ) -> ApiResult<i64> {
90        let path = format!(
91            "{}/work_item/{}/{}/workflow/task",
92            project_key, work_item_type_key, work_item_id
93        );
94        Ok(self.post(&path, request, auth).await?)
95    }
96
97    async fn update_subtask(
98        &self,
99        project_key: &str,
100        work_item_type_key: &str,
101        work_item_id: i64,
102        node_id: &str,
103        task_id: i64,
104        request: UpdateSubTaskRequest,
105        auth: AuthType,
106    ) -> ApiResult<()> {
107        let path = format!(
108            "{}/work_item/{}/{}/workflow/{}/task/{}",
109            project_key, work_item_type_key, work_item_id, node_id, task_id
110        );
111        Ok(self.post(&path, request, auth).await?)
112    }
113
114    async fn delete_subtask(
115        &self,
116        project_key: &str,
117        work_item_type_key: &str,
118        work_item_id: i64,
119        task_id: i64,
120        auth: AuthType,
121    ) -> ApiResult<()> {
122        let path = format!(
123            "{}/work_item/{}/{}/task/{}",
124            project_key, work_item_type_key, work_item_id, task_id
125        );
126        Ok(self.delete(&path, auth).await?)
127    }
128
129    async fn modify_subtask(
130        &self,
131        project_key: &str,
132        work_item_type_key: &str,
133        work_item_id: i64,
134        request: ModifySubTaskRequest,
135        auth: AuthType,
136    ) -> ApiResult<()> {
137        let path = format!(
138            "{}/work_item/{}/{}/subtask/modify",
139            project_key, work_item_type_key, work_item_id
140        );
141        Ok(self.post(&path, request, auth).await?)
142    }
143
144    async fn get_subtasks(
145        &self,
146        project_key: &str,
147        work_item_type_key: &str,
148        work_item_id: i64,
149        node_id: Option<&str>,
150        auth: AuthType,
151    ) -> ApiResult<GetSubTaskResponse> {
152        let mut path = format!(
153            "{}/work_item/{}/{}/workflow/task",
154            project_key, work_item_type_key, work_item_id
155        );
156        if let Some(node_id) = node_id {
157            path.push_str(&format!("?node_id={}", node_id));
158        }
159        Ok(self.get(&path, auth).await?)
160    }
161
162    async fn search_subtasks(
163        &self,
164        request: SearchSubTaskRequest,
165        auth: AuthType,
166    ) -> ApiResult<SearchSubTaskResponse> {
167        Ok(self.post("work_item/subtask/search", request, auth).await?)
168    }
169}