1use super::types::*;
2use crate::client::{AuthType, Client};
3use crate::error::ApiResult;
4
5pub trait SubTaskApi {
6 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 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 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 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 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 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}