1use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17#[derive(Clone, Debug, Default)]
19pub struct CreateCustomFieldParams {
20 pub custom_field_definition_json_bean: crate::models::CustomFieldDefinitionJsonBean
22}
23
24#[derive(Clone, Debug, Default)]
26pub struct DeleteCustomFieldParams {
27 pub id: String
29}
30
31#[derive(Clone, Debug, Default)]
33pub struct GetContextsForFieldDeprecatedParams {
34 pub field_id: String,
36 pub start_at: Option<i64>,
38 pub max_results: Option<i32>
40}
41
42#[derive(Clone, Debug, Default)]
44pub struct GetFieldsPaginatedParams {
45 pub start_at: Option<i64>,
47 pub max_results: Option<i32>,
49 pub _type: Option<Vec<String>>,
51 pub id: Option<Vec<String>>,
53 pub query: Option<String>,
55 pub order_by: Option<String>,
57 pub expand: Option<String>
59}
60
61#[derive(Clone, Debug, Default)]
63pub struct RestoreCustomFieldParams {
64 pub id: String
66}
67
68#[derive(Clone, Debug, Default)]
70pub struct TrashCustomFieldParams {
71 pub id: String
73}
74
75#[derive(Clone, Debug, Default)]
77pub struct UpdateCustomFieldParams {
78 pub field_id: String,
80 pub update_custom_field_details: crate::models::UpdateCustomFieldDetails
82}
83
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(untagged)]
88pub enum CreateCustomFieldError {
89 Status400(),
90 UnknownValue(serde_json::Value),
91}
92
93#[derive(Debug, Clone, Serialize, Deserialize)]
95#[serde(untagged)]
96pub enum DeleteCustomFieldError {
97 Status400(crate::models::ErrorCollection),
98 Status401(crate::models::ErrorCollection),
99 Status403(crate::models::ErrorCollection),
100 Status404(crate::models::ErrorCollection),
101 Status409(crate::models::ErrorCollection),
102 UnknownValue(serde_json::Value),
103}
104
105#[derive(Debug, Clone, Serialize, Deserialize)]
107#[serde(untagged)]
108pub enum GetContextsForFieldDeprecatedError {
109 Status401(),
110 Status403(),
111 UnknownValue(serde_json::Value),
112}
113
114#[derive(Debug, Clone, Serialize, Deserialize)]
116#[serde(untagged)]
117pub enum GetFieldsError {
118 Status401(),
119 UnknownValue(serde_json::Value),
120}
121
122#[derive(Debug, Clone, Serialize, Deserialize)]
124#[serde(untagged)]
125pub enum GetFieldsPaginatedError {
126 Status400(crate::models::ErrorCollection),
127 Status401(),
128 Status403(crate::models::ErrorCollection),
129 UnknownValue(serde_json::Value),
130}
131
132#[derive(Debug, Clone, Serialize, Deserialize)]
134#[serde(untagged)]
135pub enum RestoreCustomFieldError {
136 Status400(crate::models::ErrorCollection),
137 Status401(crate::models::ErrorCollection),
138 Status403(crate::models::ErrorCollection),
139 Status404(crate::models::ErrorCollection),
140 UnknownValue(serde_json::Value),
141}
142
143#[derive(Debug, Clone, Serialize, Deserialize)]
145#[serde(untagged)]
146pub enum TrashCustomFieldError {
147 Status400(crate::models::ErrorCollection),
148 Status401(crate::models::ErrorCollection),
149 Status403(crate::models::ErrorCollection),
150 Status404(crate::models::ErrorCollection),
151 UnknownValue(serde_json::Value),
152}
153
154#[derive(Debug, Clone, Serialize, Deserialize)]
156#[serde(untagged)]
157pub enum UpdateCustomFieldError {
158 Status400(),
159 Status401(),
160 Status403(),
161 Status404(),
162 UnknownValue(serde_json::Value),
163}
164
165
166pub async fn create_custom_field(configuration: &configuration::Configuration, params: CreateCustomFieldParams) -> Result<crate::models::FieldDetails, Error<CreateCustomFieldError>> {
168 let local_var_configuration = configuration;
169
170 let custom_field_definition_json_bean = params.custom_field_definition_json_bean;
172
173
174 let local_var_client = &local_var_configuration.client;
175
176 let local_var_uri_str = format!("{}/rest/api/2/field", local_var_configuration.base_path);
177 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
178
179 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
180 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
181 }
182 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
183 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
184 };
185 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
186 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
187 };
188 local_var_req_builder = local_var_req_builder.json(&custom_field_definition_json_bean);
189
190 let local_var_req = local_var_req_builder.build()?;
191 let local_var_resp = local_var_client.execute(local_var_req).await?;
192
193 let local_var_status = local_var_resp.status();
194 let local_var_content = local_var_resp.text().await?;
195
196 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
197 serde_json::from_str(&local_var_content).map_err(Error::from)
198 } else {
199 let local_var_entity: Option<CreateCustomFieldError> = serde_json::from_str(&local_var_content).ok();
200 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
201 Err(Error::ResponseError(local_var_error))
202 }
203}
204
205pub async fn delete_custom_field(configuration: &configuration::Configuration, params: DeleteCustomFieldParams) -> Result<(), Error<DeleteCustomFieldError>> {
207 let local_var_configuration = configuration;
208
209 let id = params.id;
211
212
213 let local_var_client = &local_var_configuration.client;
214
215 let local_var_uri_str = format!("{}/rest/api/2/field/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
216 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
217
218 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
219 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
220 }
221 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
222 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
223 };
224 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
225 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
226 };
227
228 let local_var_req = local_var_req_builder.build()?;
229 let local_var_resp = local_var_client.execute(local_var_req).await?;
230
231 let local_var_status = local_var_resp.status();
232 let local_var_content = local_var_resp.text().await?;
233
234 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
235 Ok(())
236 } else {
237 let local_var_entity: Option<DeleteCustomFieldError> = serde_json::from_str(&local_var_content).ok();
238 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
239 Err(Error::ResponseError(local_var_error))
240 }
241}
242
243pub async fn get_contexts_for_field_deprecated(configuration: &configuration::Configuration, params: GetContextsForFieldDeprecatedParams) -> Result<crate::models::PageBeanContext, Error<GetContextsForFieldDeprecatedError>> {
245 let local_var_configuration = configuration;
246
247 let field_id = params.field_id;
249 let start_at = params.start_at;
250 let max_results = params.max_results;
251
252
253 let local_var_client = &local_var_configuration.client;
254
255 let local_var_uri_str = format!("{}/rest/api/2/field/{fieldId}/contexts", local_var_configuration.base_path, fieldId=crate::apis::urlencode(field_id));
256 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
257
258 if let Some(ref local_var_str) = start_at {
259 local_var_req_builder = local_var_req_builder.query(&[("startAt", &local_var_str.to_string())]);
260 }
261 if let Some(ref local_var_str) = max_results {
262 local_var_req_builder = local_var_req_builder.query(&[("maxResults", &local_var_str.to_string())]);
263 }
264 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
265 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
266 }
267 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
268 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
269 };
270 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
271 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
272 };
273
274 let local_var_req = local_var_req_builder.build()?;
275 let local_var_resp = local_var_client.execute(local_var_req).await?;
276
277 let local_var_status = local_var_resp.status();
278 let local_var_content = local_var_resp.text().await?;
279
280 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
281 serde_json::from_str(&local_var_content).map_err(Error::from)
282 } else {
283 let local_var_entity: Option<GetContextsForFieldDeprecatedError> = serde_json::from_str(&local_var_content).ok();
284 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
285 Err(Error::ResponseError(local_var_error))
286 }
287}
288
289pub async fn get_fields(configuration: &configuration::Configuration) -> Result<Vec<crate::models::FieldDetails>, Error<GetFieldsError>> {
291 let local_var_configuration = configuration;
292
293 let local_var_client = &local_var_configuration.client;
297
298 let local_var_uri_str = format!("{}/rest/api/2/field", local_var_configuration.base_path);
299 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
300
301 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
302 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
303 }
304 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
305 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
306 };
307 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
308 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
309 };
310
311 let local_var_req = local_var_req_builder.build()?;
312 let local_var_resp = local_var_client.execute(local_var_req).await?;
313
314 let local_var_status = local_var_resp.status();
315 let local_var_content = local_var_resp.text().await?;
316
317 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
318 serde_json::from_str(&local_var_content).map_err(Error::from)
319 } else {
320 let local_var_entity: Option<GetFieldsError> = serde_json::from_str(&local_var_content).ok();
321 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
322 Err(Error::ResponseError(local_var_error))
323 }
324}
325
326pub async fn get_fields_paginated(configuration: &configuration::Configuration, params: GetFieldsPaginatedParams) -> Result<crate::models::PageBeanField, Error<GetFieldsPaginatedError>> {
328 let local_var_configuration = configuration;
329
330 let start_at = params.start_at;
332 let max_results = params.max_results;
333 let _type = params._type;
334 let id = params.id;
335 let query = params.query;
336 let order_by = params.order_by;
337 let expand = params.expand;
338
339
340 let local_var_client = &local_var_configuration.client;
341
342 let local_var_uri_str = format!("{}/rest/api/2/field/search", local_var_configuration.base_path);
343 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
344
345 if let Some(ref local_var_str) = start_at {
346 local_var_req_builder = local_var_req_builder.query(&[("startAt", &local_var_str.to_string())]);
347 }
348 if let Some(ref local_var_str) = max_results {
349 local_var_req_builder = local_var_req_builder.query(&[("maxResults", &local_var_str.to_string())]);
350 }
351 if let Some(ref local_var_str) = _type {
352 local_var_req_builder = match "multi" {
353 "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("type".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
354 _ => local_var_req_builder.query(&[("type", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
355 };
356 }
357 if let Some(ref local_var_str) = id {
358 local_var_req_builder = match "multi" {
359 "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("id".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
360 _ => local_var_req_builder.query(&[("id", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
361 };
362 }
363 if let Some(ref local_var_str) = query {
364 local_var_req_builder = local_var_req_builder.query(&[("query", &local_var_str.to_string())]);
365 }
366 if let Some(ref local_var_str) = order_by {
367 local_var_req_builder = local_var_req_builder.query(&[("orderBy", &local_var_str.to_string())]);
368 }
369 if let Some(ref local_var_str) = expand {
370 local_var_req_builder = local_var_req_builder.query(&[("expand", &local_var_str.to_string())]);
371 }
372 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
373 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
374 }
375 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
376 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
377 };
378 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
379 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
380 };
381
382 let local_var_req = local_var_req_builder.build()?;
383 let local_var_resp = local_var_client.execute(local_var_req).await?;
384
385 let local_var_status = local_var_resp.status();
386 let local_var_content = local_var_resp.text().await?;
387
388 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
389 serde_json::from_str(&local_var_content).map_err(Error::from)
390 } else {
391 let local_var_entity: Option<GetFieldsPaginatedError> = serde_json::from_str(&local_var_content).ok();
392 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
393 Err(Error::ResponseError(local_var_error))
394 }
395}
396
397pub async fn restore_custom_field(configuration: &configuration::Configuration, params: RestoreCustomFieldParams) -> Result<serde_json::Value, Error<RestoreCustomFieldError>> {
399 let local_var_configuration = configuration;
400
401 let id = params.id;
403
404
405 let local_var_client = &local_var_configuration.client;
406
407 let local_var_uri_str = format!("{}/rest/api/2/field/{id}/restore", local_var_configuration.base_path, id=crate::apis::urlencode(id));
408 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
409
410 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
411 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
412 }
413 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
414 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
415 };
416 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
417 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
418 };
419
420 let local_var_req = local_var_req_builder.build()?;
421 let local_var_resp = local_var_client.execute(local_var_req).await?;
422
423 let local_var_status = local_var_resp.status();
424 let local_var_content = local_var_resp.text().await?;
425
426 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
427 serde_json::from_str(&local_var_content).map_err(Error::from)
428 } else {
429 let local_var_entity: Option<RestoreCustomFieldError> = serde_json::from_str(&local_var_content).ok();
430 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
431 Err(Error::ResponseError(local_var_error))
432 }
433}
434
435pub async fn trash_custom_field(configuration: &configuration::Configuration, params: TrashCustomFieldParams) -> Result<serde_json::Value, Error<TrashCustomFieldError>> {
437 let local_var_configuration = configuration;
438
439 let id = params.id;
441
442
443 let local_var_client = &local_var_configuration.client;
444
445 let local_var_uri_str = format!("{}/rest/api/2/field/{id}/trash", local_var_configuration.base_path, id=crate::apis::urlencode(id));
446 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
447
448 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
449 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
450 }
451 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
452 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
453 };
454 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
455 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
456 };
457
458 let local_var_req = local_var_req_builder.build()?;
459 let local_var_resp = local_var_client.execute(local_var_req).await?;
460
461 let local_var_status = local_var_resp.status();
462 let local_var_content = local_var_resp.text().await?;
463
464 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
465 serde_json::from_str(&local_var_content).map_err(Error::from)
466 } else {
467 let local_var_entity: Option<TrashCustomFieldError> = serde_json::from_str(&local_var_content).ok();
468 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
469 Err(Error::ResponseError(local_var_error))
470 }
471}
472
473pub async fn update_custom_field(configuration: &configuration::Configuration, params: UpdateCustomFieldParams) -> Result<serde_json::Value, Error<UpdateCustomFieldError>> {
475 let local_var_configuration = configuration;
476
477 let field_id = params.field_id;
479 let update_custom_field_details = params.update_custom_field_details;
480
481
482 let local_var_client = &local_var_configuration.client;
483
484 let local_var_uri_str = format!("{}/rest/api/2/field/{fieldId}", local_var_configuration.base_path, fieldId=crate::apis::urlencode(field_id));
485 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
486
487 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
488 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
489 }
490 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
491 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
492 };
493 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
494 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
495 };
496 local_var_req_builder = local_var_req_builder.json(&update_custom_field_details);
497
498 let local_var_req = local_var_req_builder.build()?;
499 let local_var_resp = local_var_client.execute(local_var_req).await?;
500
501 let local_var_status = local_var_resp.status();
502 let local_var_content = local_var_resp.text().await?;
503
504 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
505 serde_json::from_str(&local_var_content).map_err(Error::from)
506 } else {
507 let local_var_entity: Option<UpdateCustomFieldError> = serde_json::from_str(&local_var_content).ok();
508 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
509 Err(Error::ResponseError(local_var_error))
510 }
511}
512