Skip to main content

atlassian_rust_api/jira/endpoints/components/
update_component.rs

1use std::sync::Arc;
2
3use crate::{Jira, Result, rest_client::RestClient, web::{Endpoint, JsonFormParams}};
4
5#[derive(Debug, Clone)]
6pub struct UpdateComponentBuilder {
7	client: Arc<RestClient>,
8	request: UpdateComponentRequest,
9}
10
11#[derive(Debug, Clone, Default)]
12struct UpdateComponentRequest {
13	id: u64,
14	name: Option<String>,
15	description: Option<String>,
16	lead_user_name: Option<String>,
17	assignee_type: Option<String>,
18	is_assignee_type_valid: Option<bool>,
19	project_key: Option<String>,
20	project_id: Option<u64>,
21}
22
23impl Endpoint for UpdateComponentRequest {
24	fn endpoint(&self) -> std::borrow::Cow<'static, str> {
25		format!("component/{}", self.id).into()
26	}
27
28	fn body(&self) -> Result<Option<(&'static str, Vec<u8>)>> {
29		let mut body = JsonFormParams::default();
30		body
31			.push_opt("name", self.name.as_ref())
32			.push_opt("project", self.project_key.as_ref())
33			.push_opt("projectId", self.project_id)
34			.push_opt("isAssigneeTypeValue", self.is_assignee_type_valid)
35			.push_opt("description", self.description.as_ref())
36			.push_opt("leadUserName", self.lead_user_name.as_ref())
37			.push_opt("assigneeType", self.assignee_type.as_ref());
38		body.into_body()
39	}
40}
41
42impl UpdateComponentBuilder {
43	fn new(client: Arc<RestClient>) -> UpdateComponentBuilder {
44		UpdateComponentBuilder { client, request: UpdateComponentRequest::default() }
45	}
46
47	fn id(mut self, id: u64) -> UpdateComponentBuilder {
48		self.request.id = id;
49		self
50	}
51
52	/// Update the name of the component.
53	pub fn name(mut self, name: impl Into<String>) -> UpdateComponentBuilder {
54		self.request.name = Some(name.into());
55		self
56	}
57
58	/// Update the description on the new component.
59	pub fn description(mut self, description: impl Into<String>) -> UpdateComponentBuilder {
60		self.request.description = Some(description.into());
61		self
62	}
63
64	/// Update the lead of the component.
65	pub fn lead_user_name(mut self, lead_user_name: impl Into<String>) -> UpdateComponentBuilder {
66		self.request.lead_user_name = Some(lead_user_name.into());
67		self
68	}
69
70	/// Update the assignee type of the component.
71	pub fn assignee_type(mut self, assignee_type: impl Into<String>) -> UpdateComponentBuilder {
72		self.request.assignee_type = Some(assignee_type.into());
73		self
74	}
75
76	/// Update whether the assignee type is valid or not.
77	pub fn is_assignee_type_valid(mut self, is_assignee_type_valid: bool) -> UpdateComponentBuilder {
78		self.request.is_assignee_type_valid = Some(is_assignee_type_valid);
79		self
80	}
81
82	/// Update the project key of the component.
83	pub fn project_key(mut self, project_key: impl Into<String>) -> UpdateComponentBuilder {
84		self.request.project_key = Some(project_key.into());
85		self
86	}
87
88	/// Update the project ID of the component.
89	pub fn project_id(mut self, project_id: u64) -> UpdateComponentBuilder {
90		self.request.project_id = Some(project_id);
91		self
92	}
93
94
95	pub async fn send(self) -> Result<serde_json::Value> {
96		self.client.put(self.request).await
97	}
98}
99
100impl Jira {
101	/// Modify a component. Any fields present in the request will override existing values. As a convenience, 
102	/// if a field is not present, it is silently ignored.
103	/// 
104	/// *Note*: If `lead_user_name` is an empty string (`""`) the component lead will be removed.
105	pub fn update_component(&self, id: u64) -> UpdateComponentBuilder {
106		UpdateComponentBuilder::new(Arc::clone(&self.client)).id(id)
107	}
108}