1use crate::Client;
2use crate::ClientResult;
3
4pub struct Comments {
5 pub client: Client,
6}
7
8impl Comments {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 Comments { client }
12 }
13
14 pub async fn list(
28 &self,
29 file_id: &str,
30 include_deleted: bool,
31 page_size: i64,
32 page_token: &str,
33 start_modified_time: &str,
34 ) -> ClientResult<crate::Response<Vec<crate::types::Comment>>> {
35 let mut query_args: Vec<(String, String)> = Default::default();
36 if include_deleted {
37 query_args.push(("includeDeleted".to_string(), include_deleted.to_string()));
38 }
39 if page_size > 0 {
40 query_args.push(("pageSize".to_string(), page_size.to_string()));
41 }
42 if !page_token.is_empty() {
43 query_args.push(("pageToken".to_string(), page_token.to_string()));
44 }
45 if !start_modified_time.is_empty() {
46 query_args.push((
47 "startModifiedTime".to_string(),
48 start_modified_time.to_string(),
49 ));
50 }
51 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
52 let url = self.client.url(
53 &format!(
54 "/files/{}/comments?{}",
55 crate::progenitor_support::encode_path(file_id),
56 query_
57 ),
58 None,
59 );
60 let resp: crate::Response<crate::types::CommentList> = self
61 .client
62 .get(
63 &url,
64 crate::Message {
65 body: None,
66 content_type: None,
67 },
68 )
69 .await?;
70
71 Ok(crate::Response::new(
73 resp.status,
74 resp.headers,
75 resp.body.comments.to_vec(),
76 ))
77 }
78 pub async fn list_all(
86 &self,
87 file_id: &str,
88 include_deleted: bool,
89 start_modified_time: &str,
90 ) -> ClientResult<crate::Response<Vec<crate::types::Comment>>> {
91 let mut query_args: Vec<(String, String)> = Default::default();
92 if include_deleted {
93 query_args.push(("includeDeleted".to_string(), include_deleted.to_string()));
94 }
95 if !start_modified_time.is_empty() {
96 query_args.push((
97 "startModifiedTime".to_string(),
98 start_modified_time.to_string(),
99 ));
100 }
101 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
102 let url = self.client.url(
103 &format!(
104 "/files/{}/comments?{}",
105 crate::progenitor_support::encode_path(file_id),
106 query_
107 ),
108 None,
109 );
110 let crate::Response::<crate::types::CommentList> {
111 mut status,
112 mut headers,
113 mut body,
114 } = self
115 .client
116 .get(
117 &url,
118 crate::Message {
119 body: None,
120 content_type: None,
121 },
122 )
123 .await?;
124
125 let mut comments = body.comments;
126 let mut page = body.next_page_token;
127
128 while !page.is_empty() {
130 if !url.contains('?') {
131 crate::Response::<crate::types::CommentList> {
132 status,
133 headers,
134 body,
135 } = self
136 .client
137 .get(
138 &format!("{}?pageToken={}", url, page),
139 crate::Message {
140 body: None,
141 content_type: None,
142 },
143 )
144 .await?;
145 } else {
146 crate::Response::<crate::types::CommentList> {
147 status,
148 headers,
149 body,
150 } = self
151 .client
152 .get(
153 &format!("{}&pageToken={}", url, page),
154 crate::Message {
155 body: None,
156 content_type: None,
157 },
158 )
159 .await?;
160 }
161
162 comments.append(&mut body.comments);
163
164 if !body.next_page_token.is_empty() && body.next_page_token != page {
165 page = body.next_page_token.to_string();
166 } else {
167 page = "".to_string();
168 }
169 }
170
171 Ok(crate::Response::new(status, headers, comments))
173 }
174 pub async fn create(
184 &self,
185 file_id: &str,
186 body: &crate::types::Comment,
187 ) -> ClientResult<crate::Response<crate::types::Comment>> {
188 let url = self.client.url(
189 &format!(
190 "/files/{}/comments",
191 crate::progenitor_support::encode_path(file_id),
192 ),
193 None,
194 );
195 self.client
196 .post(
197 &url,
198 crate::Message {
199 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
200 content_type: Some("application/json".to_string()),
201 },
202 )
203 .await
204 }
205 pub async fn get(
217 &self,
218 file_id: &str,
219 comment_id: &str,
220 include_deleted: bool,
221 ) -> ClientResult<crate::Response<crate::types::Comment>> {
222 let mut query_args: Vec<(String, String)> = Default::default();
223 if include_deleted {
224 query_args.push(("includeDeleted".to_string(), include_deleted.to_string()));
225 }
226 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
227 let url = self.client.url(
228 &format!(
229 "/files/{}/comments/{}?{}",
230 crate::progenitor_support::encode_path(file_id),
231 crate::progenitor_support::encode_path(comment_id),
232 query_
233 ),
234 None,
235 );
236 self.client
237 .get(
238 &url,
239 crate::Message {
240 body: None,
241 content_type: None,
242 },
243 )
244 .await
245 }
246 pub async fn delete(
257 &self,
258 file_id: &str,
259 comment_id: &str,
260 ) -> ClientResult<crate::Response<()>> {
261 let url = self.client.url(
262 &format!(
263 "/files/{}/comments/{}",
264 crate::progenitor_support::encode_path(file_id),
265 crate::progenitor_support::encode_path(comment_id),
266 ),
267 None,
268 );
269 self.client
270 .delete(
271 &url,
272 crate::Message {
273 body: None,
274 content_type: None,
275 },
276 )
277 .await
278 }
279 pub async fn update(
290 &self,
291 file_id: &str,
292 comment_id: &str,
293 body: &crate::types::Comment,
294 ) -> ClientResult<crate::Response<crate::types::Comment>> {
295 let url = self.client.url(
296 &format!(
297 "/files/{}/comments/{}",
298 crate::progenitor_support::encode_path(file_id),
299 crate::progenitor_support::encode_path(comment_id),
300 ),
301 None,
302 );
303 self.client
304 .patch(
305 &url,
306 crate::Message {
307 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
308 content_type: Some("application/json".to_string()),
309 },
310 )
311 .await
312 }
313}