benchling/request/
update_plate.rs

1use serde_json::json;
2use crate::model::*;
3use crate::BenchlingClient;
4/**Create this with the associated client method.
5
6That method takes required values as arguments. Set optional values using builder methods on this struct.*/
7pub struct UpdatePlateRequest<'a> {
8    pub(crate) client: &'a BenchlingClient,
9    pub plate_id: String,
10    pub returning: Option<String>,
11    pub fields: Option<Fields>,
12    pub name: Option<String>,
13    pub parent_storage_id: Option<String>,
14    pub project_id: Option<String>,
15}
16impl<'a> UpdatePlateRequest<'a> {
17    pub async fn send(self) -> anyhow::Result<Plate> {
18        let mut r = self
19            .client
20            .client
21            .patch(&format!("/plates/{plate_id}", plate_id = self.plate_id));
22        if let Some(ref unwrapped) = self.returning {
23            r = r.push_query("returning", &unwrapped.to_string());
24        }
25        if let Some(ref unwrapped) = self.fields {
26            r = r.push_json(json!({ "fields" : unwrapped }));
27        }
28        if let Some(ref unwrapped) = self.name {
29            r = r.push_json(json!({ "name" : unwrapped }));
30        }
31        if let Some(ref unwrapped) = self.parent_storage_id {
32            r = r.push_json(json!({ "parentStorageId" : unwrapped }));
33        }
34        if let Some(ref unwrapped) = self.project_id {
35            r = r.push_json(json!({ "projectId" : unwrapped }));
36        }
37        r = self.client.authenticate(r);
38        let res = r.send().await.unwrap().error_for_status();
39        match res {
40            Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
41            Err(res) => {
42                let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
43                Err(anyhow::anyhow!("{:?}", text))
44            }
45        }
46    }
47    pub fn returning(mut self, returning: &str) -> Self {
48        self.returning = Some(returning.to_owned());
49        self
50    }
51    pub fn fields(mut self, fields: Fields) -> Self {
52        self.fields = Some(fields);
53        self
54    }
55    pub fn name(mut self, name: &str) -> Self {
56        self.name = Some(name.to_owned());
57        self
58    }
59    pub fn parent_storage_id(mut self, parent_storage_id: &str) -> Self {
60        self.parent_storage_id = Some(parent_storage_id.to_owned());
61        self
62    }
63    pub fn project_id(mut self, project_id: &str) -> Self {
64        self.project_id = Some(project_id.to_owned());
65        self
66    }
67}