1use serde_json::Value;
2
3use super::types::*;
4use crate::client::{AuthType, Client};
5use crate::error::ApiResult;
6
7pub trait WorkItemApi {
8 fn filter_work_items_in_project(
10 &self,
11 project_key: String,
12 request: FilterWorkItemsInProjectRequest,
13 auth: AuthType,
14 ) -> impl std::future::Future<Output = ApiResult<FilterWorkItemsInProjectResponse>> + Send;
15
16 fn filter_work_items_across_projects(
18 &self,
19 request: FilterWorkItemsAcrossProjectsRequest,
20 auth: AuthType,
21 ) -> impl std::future::Future<Output = ApiResult<FilterWorkItemsAcrossProjectsResponse>> + Send;
22
23 fn search_work_items_in_project(
26 &self,
27 project_key: String,
28 work_item_type_key: String,
29 request: SearchWorkItemsInProjectRequest,
30 auth: AuthType,
31 ) -> impl std::future::Future<Output = ApiResult<SearchWorkItemsInProjectResponse>> + Send;
32
33 fn compositive_search(
36 &self,
37 request: CompositiveSearchRequest,
38 auth: AuthType,
39 ) -> impl std::future::Future<Output = ApiResult<CompositiveSearchResponse>> + Send;
40
41 fn search_work_items_by_relation(
44 &self,
45 project_key: String,
46 work_item_type_key: String,
47 work_item_id: String,
48 request: SearchWorkItemsByRelationRequest,
49 auth: AuthType,
50 ) -> impl std::future::Future<Output = ApiResult<SearchWorkItemsByRelationResponse>> + Send;
51
52 fn get_work_item_details(
55 &self,
56 project_key: String,
57 work_item_type_key: String,
58 request: GetWorkItemDetailsRequest,
59 auth: AuthType,
60 ) -> impl std::future::Future<Output = ApiResult<GetWorkItemDetailsResponse>> + Send;
61
62 fn get_work_item_meta(
65 &self,
66 project_key: String,
67 work_item_type_key: String,
68 auth: AuthType,
69 ) -> impl std::future::Future<Output = ApiResult<GetWorkItemMetaResponse>> + Send;
70
71 fn create_work_item(
74 &self,
75 project_key: String,
76 request: CreateWorkItemRequest,
77 auth: AuthType,
78 ) -> impl std::future::Future<Output = ApiResult<CreateWorkItemResponse>> + Send;
79
80 fn update_work_item(
83 &self,
84 project_key: String,
85 work_item_type_key: String,
86 work_item_id: String,
87 request: UpdateWorkItemRequest,
88 auth: AuthType,
89 ) -> impl std::future::Future<Output = ApiResult<UpdateWorkItemResponse>> + Send;
90
91 fn batch_update_work_items(
94 &self,
95 request: BatchUpdateWorkItemRequest,
96 auth: AuthType,
97 ) -> impl std::future::Future<Output = ApiResult<BatchUpdateWorkItemResponse>> + Send;
98
99 fn get_batch_update_result(
102 &self,
103 task_id: String,
104 auth: AuthType,
105 ) -> impl std::future::Future<Output = ApiResult<TaskResultResponse>> + Send;
106
107 fn batch_query_deliverable(
110 &self,
111 request: BatchQueryDeliverableRequest,
112 auth: AuthType,
113 ) -> impl std::future::Future<Output = ApiResult<BatchQueryDeliverableResponse>> + Send;
114
115 fn delete_work_item(
118 &self,
119 project_key: String,
120 work_item_type_key: String,
121 work_item_id: i64,
122 auth: AuthType,
123 ) -> impl std::future::Future<Output = ApiResult<Value>> + Send;
124
125 fn abort_work_item(
128 &self,
129 project_key: String,
130 work_item_type_key: String,
131 work_item_id: i64,
132 request: AbortWorkItemRequest,
133 auth: AuthType,
134 ) -> impl std::future::Future<Output = ApiResult<AbortWorkItemResponse>> + Send;
135
136 fn freeze_work_item(
139 &self,
140 request: FreezeWorkItemRequest,
141 auth: AuthType,
142 ) -> impl std::future::Future<Output = ApiResult<FreezeWorkItemResponse>> + Send;
143
144 fn get_work_item_operation_records(
147 &self,
148 request: GetWorkItemOperationRecordRequest,
149 auth: AuthType,
150 ) -> impl std::future::Future<Output = ApiResult<GetWorkItemOperationRecordResponse>> + Send;
151}
152
153impl WorkItemApi for Client {
154 async fn filter_work_items_in_project(
155 &self,
156 project_key: String,
157 request: FilterWorkItemsInProjectRequest,
158 auth: AuthType,
159 ) -> ApiResult<FilterWorkItemsInProjectResponse> {
160 Ok(self
161 .post(format!("{}/work_item/filter", project_key), request, auth)
162 .await?)
163 }
164
165 async fn filter_work_items_across_projects(
166 &self,
167 request: FilterWorkItemsAcrossProjectsRequest,
168 auth: AuthType,
169 ) -> ApiResult<FilterWorkItemsAcrossProjectsResponse> {
170 Ok(self
171 .post("work_items/filter_across_project", request, auth)
172 .await?)
173 }
174
175 async fn search_work_items_in_project(
176 &self,
177 project_key: String,
178 work_item_type_key: String,
179 request: SearchWorkItemsInProjectRequest,
180 auth: AuthType,
181 ) -> ApiResult<SearchWorkItemsInProjectResponse> {
182 Ok(self
183 .post(
184 format!(
185 "{}/work_item/{}/search/params",
186 project_key, work_item_type_key
187 ),
188 request,
189 auth,
190 )
191 .await?)
192 }
193
194 async fn compositive_search(
195 &self,
196 request: CompositiveSearchRequest,
197 auth: AuthType,
198 ) -> ApiResult<CompositiveSearchResponse> {
199 Ok(self
200 .post("compositive_search", request, auth)
201 .await?)
202 }
203
204 async fn search_work_items_by_relation(
205 &self,
206 project_key: String,
207 work_item_type_key: String,
208 work_item_id: String,
209 request: SearchWorkItemsByRelationRequest,
210 auth: AuthType,
211 ) -> ApiResult<SearchWorkItemsByRelationResponse> {
212 Ok(self
213 .post(
214 format!(
215 "{}/work_item/{}/{}/search_by_relation",
216 project_key, work_item_type_key, work_item_id
217 ),
218 request,
219 auth,
220 )
221 .await?)
222 }
223
224 async fn get_work_item_details(
225 &self,
226 project_key: String,
227 work_item_type_key: String,
228 request: GetWorkItemDetailsRequest,
229 auth: AuthType,
230 ) -> ApiResult<GetWorkItemDetailsResponse> {
231 Ok(self
232 .post(
233 format!("{}/work_item/{}/query", project_key, work_item_type_key),
234 request,
235 auth,
236 )
237 .await?)
238 }
239
240 async fn get_work_item_meta(
241 &self,
242 project_key: String,
243 work_item_type_key: String,
244 auth: AuthType,
245 ) -> ApiResult<GetWorkItemMetaResponse> {
246 Ok(self
247 .get(
248 format!("{}/work_item/{}/meta", project_key, work_item_type_key),
249 auth,
250 )
251 .await?)
252 }
253
254 async fn create_work_item(
255 &self,
256 project_key: String,
257 request: CreateWorkItemRequest,
258 auth: AuthType,
259 ) -> ApiResult<CreateWorkItemResponse> {
260 Ok(self
261 .post(format!("{}/work_item/create", project_key), request, auth)
262 .await?)
263 }
264
265 async fn update_work_item(
266 &self,
267 project_key: String,
268 work_item_type_key: String,
269 work_item_id: String,
270 request: UpdateWorkItemRequest,
271 auth: AuthType,
272 ) -> ApiResult<UpdateWorkItemResponse> {
273 Ok(self
274 .put(
275 format!(
276 "{}/work_item/{}/{}",
277 project_key, work_item_type_key, work_item_id
278 ),
279 request,
280 auth,
281 )
282 .await?)
283 }
284
285 async fn batch_update_work_items(
286 &self,
287 request: BatchUpdateWorkItemRequest,
288 auth: AuthType,
289 ) -> ApiResult<BatchUpdateWorkItemResponse> {
290 Ok(self.post("work_item/batch_update", request, auth).await?)
291 }
292
293 async fn get_batch_update_result(
294 &self,
295 task_id: String,
296 auth: AuthType,
297 ) -> ApiResult<TaskResultResponse> {
298 Ok(self
299 .get(format!("task_result?task_id={}", task_id), auth)
300 .await?)
301 }
302
303 async fn batch_query_deliverable(
304 &self,
305 request: BatchQueryDeliverableRequest,
306 auth: AuthType,
307 ) -> ApiResult<BatchQueryDeliverableResponse> {
308 Ok(self
309 .post("work_item/deliverable/batch_query", request, auth)
310 .await?)
311 }
312
313 async fn delete_work_item(
314 &self,
315 project_key: String,
316 work_item_type_key: String,
317 work_item_id: i64,
318 auth: AuthType,
319 ) -> ApiResult<Value> {
320 Ok(self
321 .delete(
322 format!(
323 "{}/work_item/{}/{}",
324 project_key, work_item_type_key, work_item_id
325 ),
326 auth,
327 )
328 .await?)
329 }
330
331 async fn abort_work_item(
332 &self,
333 project_key: String,
334 work_item_type_key: String,
335 work_item_id: i64,
336 request: AbortWorkItemRequest,
337 auth: AuthType,
338 ) -> ApiResult<AbortWorkItemResponse> {
339 Ok(self
340 .put(
341 format!(
342 "{}/work_item/{}/{}/abort",
343 project_key, work_item_type_key, work_item_id
344 ),
345 request,
346 auth,
347 )
348 .await?)
349 }
350
351 async fn freeze_work_item(
352 &self,
353 request: FreezeWorkItemRequest,
354 auth: AuthType,
355 ) -> ApiResult<FreezeWorkItemResponse> {
356 Ok(self.put("work_item/freeze", request, auth).await?)
357 }
358
359 async fn get_work_item_operation_records(
360 &self,
361 request: GetWorkItemOperationRecordRequest,
362 auth: AuthType,
363 ) -> ApiResult<GetWorkItemOperationRecordResponse> {
364 Ok(self
365 .post("op_record/work_item/list", request, auth)
366 .await?)
367 }
368}