1use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17#[derive(Clone, Debug, Default)]
19pub struct CreateCustomFieldOptionParams {
20 pub field_id: String,
22 pub context_id: i64,
24 pub bulk_custom_field_option_create_request: crate::models::BulkCustomFieldOptionCreateRequest
25}
26
27#[derive(Clone, Debug, Default)]
29pub struct DeleteCustomFieldOptionParams {
30 pub field_id: String,
32 pub context_id: i64,
34 pub option_id: i64
36}
37
38#[derive(Clone, Debug, Default)]
40pub struct GetCustomFieldOptionParams {
41 pub id: String
43}
44
45#[derive(Clone, Debug, Default)]
47pub struct GetOptionsForContextParams {
48 pub field_id: String,
50 pub context_id: i64,
52 pub option_id: Option<i64>,
54 pub only_options: Option<bool>,
56 pub start_at: Option<i64>,
58 pub max_results: Option<i32>
60}
61
62#[derive(Clone, Debug, Default)]
64pub struct ReorderCustomFieldOptionsParams {
65 pub field_id: String,
67 pub context_id: i64,
69 pub order_of_custom_field_options: crate::models::OrderOfCustomFieldOptions
70}
71
72#[derive(Clone, Debug, Default)]
74pub struct UpdateCustomFieldOptionParams {
75 pub field_id: String,
77 pub context_id: i64,
79 pub bulk_custom_field_option_update_request: crate::models::BulkCustomFieldOptionUpdateRequest
80}
81
82
83#[derive(Debug, Clone, Serialize, Deserialize)]
85#[serde(untagged)]
86pub enum CreateCustomFieldOptionError {
87 Status400(),
88 Status401(),
89 Status403(),
90 Status404(),
91 UnknownValue(serde_json::Value),
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize)]
96#[serde(untagged)]
97pub enum DeleteCustomFieldOptionError {
98 Status400(),
99 Status401(),
100 Status403(),
101 Status404(),
102 UnknownValue(serde_json::Value),
103}
104
105#[derive(Debug, Clone, Serialize, Deserialize)]
107#[serde(untagged)]
108pub enum GetCustomFieldOptionError {
109 Status401(),
110 Status404(),
111 UnknownValue(serde_json::Value),
112}
113
114#[derive(Debug, Clone, Serialize, Deserialize)]
116#[serde(untagged)]
117pub enum GetOptionsForContextError {
118 Status400(),
119 Status401(),
120 Status403(),
121 Status404(),
122 UnknownValue(serde_json::Value),
123}
124
125#[derive(Debug, Clone, Serialize, Deserialize)]
127#[serde(untagged)]
128pub enum ReorderCustomFieldOptionsError {
129 Status400(),
130 Status401(),
131 Status403(),
132 Status404(),
133 UnknownValue(serde_json::Value),
134}
135
136#[derive(Debug, Clone, Serialize, Deserialize)]
138#[serde(untagged)]
139pub enum UpdateCustomFieldOptionError {
140 Status400(),
141 Status401(),
142 Status403(),
143 Status404(),
144 UnknownValue(serde_json::Value),
145}
146
147
148pub async fn create_custom_field_option(configuration: &configuration::Configuration, params: CreateCustomFieldOptionParams) -> Result<crate::models::CustomFieldCreatedContextOptionsList, Error<CreateCustomFieldOptionError>> {
150 let local_var_configuration = configuration;
151
152 let field_id = params.field_id;
154 let context_id = params.context_id;
155 let bulk_custom_field_option_create_request = params.bulk_custom_field_option_create_request;
156
157
158 let local_var_client = &local_var_configuration.client;
159
160 let local_var_uri_str = format!("{}/rest/api/2/field/{fieldId}/context/{contextId}/option", local_var_configuration.base_path, fieldId=crate::apis::urlencode(field_id), contextId=context_id);
161 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
162
163 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
164 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
165 }
166 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
167 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
168 };
169 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
170 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
171 };
172 local_var_req_builder = local_var_req_builder.json(&bulk_custom_field_option_create_request);
173
174 let local_var_req = local_var_req_builder.build()?;
175 let local_var_resp = local_var_client.execute(local_var_req).await?;
176
177 let local_var_status = local_var_resp.status();
178 let local_var_content = local_var_resp.text().await?;
179
180 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
181 serde_json::from_str(&local_var_content).map_err(Error::from)
182 } else {
183 let local_var_entity: Option<CreateCustomFieldOptionError> = serde_json::from_str(&local_var_content).ok();
184 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
185 Err(Error::ResponseError(local_var_error))
186 }
187}
188
189pub async fn delete_custom_field_option(configuration: &configuration::Configuration, params: DeleteCustomFieldOptionParams) -> Result<(), Error<DeleteCustomFieldOptionError>> {
191 let local_var_configuration = configuration;
192
193 let field_id = params.field_id;
195 let context_id = params.context_id;
196 let option_id = params.option_id;
197
198
199 let local_var_client = &local_var_configuration.client;
200
201 let local_var_uri_str = format!("{}/rest/api/2/field/{fieldId}/context/{contextId}/option/{optionId}", local_var_configuration.base_path, fieldId=crate::apis::urlencode(field_id), contextId=context_id, optionId=option_id);
202 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
203
204 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
205 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
206 }
207 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
208 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
209 };
210 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
211 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
212 };
213
214 let local_var_req = local_var_req_builder.build()?;
215 let local_var_resp = local_var_client.execute(local_var_req).await?;
216
217 let local_var_status = local_var_resp.status();
218 let local_var_content = local_var_resp.text().await?;
219
220 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
221 Ok(())
222 } else {
223 let local_var_entity: Option<DeleteCustomFieldOptionError> = serde_json::from_str(&local_var_content).ok();
224 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
225 Err(Error::ResponseError(local_var_error))
226 }
227}
228
229pub async fn get_custom_field_option(configuration: &configuration::Configuration, params: GetCustomFieldOptionParams) -> Result<crate::models::CustomFieldOption, Error<GetCustomFieldOptionError>> {
231 let local_var_configuration = configuration;
232
233 let id = params.id;
235
236
237 let local_var_client = &local_var_configuration.client;
238
239 let local_var_uri_str = format!("{}/rest/api/2/customFieldOption/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
240 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
241
242 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
243 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
244 }
245 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
246 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
247 };
248 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
249 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
250 };
251
252 let local_var_req = local_var_req_builder.build()?;
253 let local_var_resp = local_var_client.execute(local_var_req).await?;
254
255 let local_var_status = local_var_resp.status();
256 let local_var_content = local_var_resp.text().await?;
257
258 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
259 serde_json::from_str(&local_var_content).map_err(Error::from)
260 } else {
261 let local_var_entity: Option<GetCustomFieldOptionError> = serde_json::from_str(&local_var_content).ok();
262 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
263 Err(Error::ResponseError(local_var_error))
264 }
265}
266
267pub async fn get_options_for_context(configuration: &configuration::Configuration, params: GetOptionsForContextParams) -> Result<crate::models::PageBeanCustomFieldContextOption, Error<GetOptionsForContextError>> {
269 let local_var_configuration = configuration;
270
271 let field_id = params.field_id;
273 let context_id = params.context_id;
274 let option_id = params.option_id;
275 let only_options = params.only_options;
276 let start_at = params.start_at;
277 let max_results = params.max_results;
278
279
280 let local_var_client = &local_var_configuration.client;
281
282 let local_var_uri_str = format!("{}/rest/api/2/field/{fieldId}/context/{contextId}/option", local_var_configuration.base_path, fieldId=crate::apis::urlencode(field_id), contextId=context_id);
283 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
284
285 if let Some(ref local_var_str) = option_id {
286 local_var_req_builder = local_var_req_builder.query(&[("optionId", &local_var_str.to_string())]);
287 }
288 if let Some(ref local_var_str) = only_options {
289 local_var_req_builder = local_var_req_builder.query(&[("onlyOptions", &local_var_str.to_string())]);
290 }
291 if let Some(ref local_var_str) = start_at {
292 local_var_req_builder = local_var_req_builder.query(&[("startAt", &local_var_str.to_string())]);
293 }
294 if let Some(ref local_var_str) = max_results {
295 local_var_req_builder = local_var_req_builder.query(&[("maxResults", &local_var_str.to_string())]);
296 }
297 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
298 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
299 }
300 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
301 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
302 };
303 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
304 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
305 };
306
307 let local_var_req = local_var_req_builder.build()?;
308 let local_var_resp = local_var_client.execute(local_var_req).await?;
309
310 let local_var_status = local_var_resp.status();
311 let local_var_content = local_var_resp.text().await?;
312
313 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
314 serde_json::from_str(&local_var_content).map_err(Error::from)
315 } else {
316 let local_var_entity: Option<GetOptionsForContextError> = serde_json::from_str(&local_var_content).ok();
317 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
318 Err(Error::ResponseError(local_var_error))
319 }
320}
321
322pub async fn reorder_custom_field_options(configuration: &configuration::Configuration, params: ReorderCustomFieldOptionsParams) -> Result<serde_json::Value, Error<ReorderCustomFieldOptionsError>> {
324 let local_var_configuration = configuration;
325
326 let field_id = params.field_id;
328 let context_id = params.context_id;
329 let order_of_custom_field_options = params.order_of_custom_field_options;
330
331
332 let local_var_client = &local_var_configuration.client;
333
334 let local_var_uri_str = format!("{}/rest/api/2/field/{fieldId}/context/{contextId}/option/move", local_var_configuration.base_path, fieldId=crate::apis::urlencode(field_id), contextId=context_id);
335 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
336
337 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
338 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
339 }
340 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
341 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
342 };
343 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
344 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
345 };
346 local_var_req_builder = local_var_req_builder.json(&order_of_custom_field_options);
347
348 let local_var_req = local_var_req_builder.build()?;
349 let local_var_resp = local_var_client.execute(local_var_req).await?;
350
351 let local_var_status = local_var_resp.status();
352 let local_var_content = local_var_resp.text().await?;
353
354 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
355 serde_json::from_str(&local_var_content).map_err(Error::from)
356 } else {
357 let local_var_entity: Option<ReorderCustomFieldOptionsError> = serde_json::from_str(&local_var_content).ok();
358 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
359 Err(Error::ResponseError(local_var_error))
360 }
361}
362
363pub async fn update_custom_field_option(configuration: &configuration::Configuration, params: UpdateCustomFieldOptionParams) -> Result<crate::models::CustomFieldUpdatedContextOptionsList, Error<UpdateCustomFieldOptionError>> {
365 let local_var_configuration = configuration;
366
367 let field_id = params.field_id;
369 let context_id = params.context_id;
370 let bulk_custom_field_option_update_request = params.bulk_custom_field_option_update_request;
371
372
373 let local_var_client = &local_var_configuration.client;
374
375 let local_var_uri_str = format!("{}/rest/api/2/field/{fieldId}/context/{contextId}/option", local_var_configuration.base_path, fieldId=crate::apis::urlencode(field_id), contextId=context_id);
376 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
377
378 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
379 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
380 }
381 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
382 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
383 };
384 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
385 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
386 };
387 local_var_req_builder = local_var_req_builder.json(&bulk_custom_field_option_update_request);
388
389 let local_var_req = local_var_req_builder.build()?;
390 let local_var_resp = local_var_client.execute(local_var_req).await?;
391
392 let local_var_status = local_var_resp.status();
393 let local_var_content = local_var_resp.text().await?;
394
395 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
396 serde_json::from_str(&local_var_content).map_err(Error::from)
397 } else {
398 let local_var_entity: Option<UpdateCustomFieldOptionError> = serde_json::from_str(&local_var_content).ok();
399 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
400 Err(Error::ResponseError(local_var_error))
401 }
402}
403