Skip to main content

atlassian_rust_api/jira/endpoints/components/
delete_component.rs

1use std::sync::Arc;
2
3use crate::{Jira, Result, rest_client::RestClient, web::{Endpoint, QueryParams}};
4
5#[derive(Debug, Clone)]
6pub struct DeleteComponentBuilder {
7	client: Arc<RestClient>,
8	request: DeleteComponentRequest,
9}
10
11#[derive(Debug, Clone, Default)]
12struct DeleteComponentRequest {
13	id: u64,
14	move_issues_to: Option<u64>,
15}
16
17impl Endpoint for DeleteComponentRequest {
18	fn endpoint(&self) -> std::borrow::Cow<'static, str> {
19		format!("component/{}", self.id).into()
20	}
21
22	fn parameters(&self) -> crate::web::QueryParams<'_> {
23		let mut params = QueryParams::default();
24		params.push_opt("moveIssuesTo", self.move_issues_to);
25		params
26	}
27}
28
29impl DeleteComponentBuilder {
30	fn new(client: Arc<RestClient>) -> DeleteComponentBuilder {
31		DeleteComponentBuilder { client, request: DeleteComponentRequest::default() }
32	}
33
34	fn id(mut self, id: u64) -> DeleteComponentBuilder {
35		self.request.id = id;
36		self
37	}
38
39	/// The new component applied to issues whose 'id' component will be deleted. If this value is null, 
40	/// then the 'id' component is simply removed from the related isues.
41	pub fn move_issues_to(mut self, move_issues_to: u64) -> DeleteComponentBuilder {
42		self.request.move_issues_to = Some(move_issues_to);
43		self
44	}
45
46	pub async fn send(self) -> Result<()> {
47		self.client.delete_ignore(self.request).await
48	}
49}
50
51impl Jira {
52	/// Delete a project component.
53	pub fn delete_component(&self, id: u64) -> DeleteComponentBuilder {
54		DeleteComponentBuilder::new(Arc::clone(&self.client)).id(id)
55	}
56}