1use super::types::*;
2use crate::client::{AuthType, Client};
3use crate::error::ApiResult;
4
5pub trait CommentApi {
6 fn create_comment(
9 &self,
10 request: CreateCommentRequest,
11 auth: AuthType,
12 ) -> impl std::future::Future<Output = ApiResult<CreateCommentResponse>> + Send;
13
14 fn get_comments(
17 &self,
18 request: GetCommentsRequest,
19 auth: AuthType,
20 ) -> impl std::future::Future<Output = ApiResult<GetCommentsResponse>> + Send;
21
22 fn update_comment(
25 &self,
26 request: UpdateCommentRequest,
27 auth: AuthType,
28 ) -> impl std::future::Future<Output = ApiResult<UpdateCommentResponse>> + Send;
29
30 fn delete_comment(
33 &self,
34 request: DeleteCommentRequest,
35 auth: AuthType,
36 ) -> impl std::future::Future<Output = ApiResult<DeleteCommentResponse>> + Send;
37}
38
39impl CommentApi for Client {
40 async fn create_comment(
41 &self,
42 request: CreateCommentRequest,
43 auth: AuthType,
44 ) -> ApiResult<CreateCommentResponse> {
45 Ok(self
46 .post(
47 &format!(
48 "{}/work_item/{}/{}/comment/create",
49 request.project_key, request.work_item_type_key, request.work_item_id
50 ),
51 &request,
52 auth,
53 )
54 .await?)
55 }
56
57 async fn get_comments(
58 &self,
59 request: GetCommentsRequest,
60 auth: AuthType,
61 ) -> ApiResult<GetCommentsResponse> {
62 let mut url = format!(
63 "{}/work_item/{}/{}/comments",
64 request.project_key, request.work_item_type_key, request.work_item_id
65 );
66
67 if let Some(page_size) = request.page_size {
68 url.push_str(&format!("?page_size={}", page_size));
69 if let Some(page_num) = request.page_num {
70 url.push_str(&format!("&page_num={}", page_num));
71 }
72 }
73
74 Ok(self.get(&url, auth).await?)
75 }
76
77 async fn update_comment(
78 &self,
79 request: UpdateCommentRequest,
80 auth: AuthType,
81 ) -> ApiResult<UpdateCommentResponse> {
82 Ok(self
83 .put(
84 &format!(
85 "{}/work_item/{}/{}/comment/{}",
86 request.project_key,
87 request.work_item_type_key,
88 request.work_item_id,
89 request.comment_id
90 ),
91 &request,
92 auth,
93 )
94 .await?)
95 }
96
97 async fn delete_comment(
98 &self,
99 request: DeleteCommentRequest,
100 auth: AuthType,
101 ) -> ApiResult<DeleteCommentResponse> {
102 Ok(self
103 .delete(
104 &format!(
105 "{}/work_item/{}/{}/comment/{}",
106 request.project_key,
107 request.work_item_type_key,
108 request.work_item_id,
109 request.comment_id
110 ),
111 auth,
112 )
113 .await?)
114 }
115}