Skip to main content

atlassian_rust_api/jira/endpoints/application_properties/
set_property.rs

1use std::sync::Arc;
2
3use crate::{Jira, Result, rest_client::RestClient, web::{Endpoint, JsonFormParams}};
4
5#[derive(Debug, Clone)]
6pub struct SetPropertyBuilder {
7	client: Arc<RestClient>,
8	request: SetPropertyRequest,
9}
10
11#[derive(Debug, Clone, Default)]
12struct SetPropertyRequest {
13	id: String,
14	value: String,
15}
16
17impl Endpoint for SetPropertyRequest {
18	fn endpoint(&self) -> std::borrow::Cow<'static, str> {
19		format!("application-properties/{}", self.id.clone()).into()
20	}
21
22	fn body(&self) -> Result<Option<(&'static str, Vec<u8>)>> {
23		let mut body = JsonFormParams::default();
24		body
25			.push("id", &self.id)
26			.push("value", &self.value);
27		body.into_body()
28	}
29}
30
31impl SetPropertyBuilder {
32	fn new(client: Arc<RestClient>) -> SetPropertyBuilder {
33		SetPropertyBuilder { client, request: SetPropertyRequest::default() }
34	}
35
36	fn id(mut self, id: impl Into<String>) -> SetPropertyBuilder {
37		self.request.id = id.into();
38		self
39	}
40
41	fn value(mut self, value: impl Into<String>) -> SetPropertyBuilder {
42		self.request.value = value.into();
43		self
44	}
45
46	pub async fn send(self) -> Result<()> {
47		self.client.put_ignore(self.request).await
48	}
49}
50
51impl Jira {
52	/// Modify an application property via PUT. The "value" field present in the PUT will override the
53	/// existing value.
54	pub fn set_property(&self, id: impl Into<String>, value: impl Into<String>) -> SetPropertyBuilder {
55		SetPropertyBuilder::new(Arc::clone(&self.client)).id(id).value(value)
56	}
57}