Skip to main content

asana/request/
create_subtask_for_task.rs

1use serde_json::json;
2use crate::model::*;
3use crate::FluentRequest;
4use serde::{Serialize, Deserialize};
5use httpclient::InMemoryResponseExt;
6use crate::AsanaClient;
7/**You should use this struct via [`AsanaClient::create_subtask_for_task`].
8
9On request success, this will return a [`CreateSubtaskForTaskResponse`].*/
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct CreateSubtaskForTaskRequest {
12    pub data: TaskRequest,
13    pub opt_fields: Option<Vec<String>>,
14    pub opt_pretty: Option<bool>,
15    pub task_gid: String,
16}
17impl CreateSubtaskForTaskRequest {}
18impl FluentRequest<'_, CreateSubtaskForTaskRequest> {
19    pub fn opt_fields(
20        mut self,
21        opt_fields: impl IntoIterator<Item = impl AsRef<str>>,
22    ) -> Self {
23        self
24            .params
25            .opt_fields = Some(
26            opt_fields.into_iter().map(|s| s.as_ref().to_owned()).collect(),
27        );
28        self
29    }
30    pub fn opt_pretty(mut self, opt_pretty: bool) -> Self {
31        self.params.opt_pretty = Some(opt_pretty);
32        self
33    }
34}
35impl<'a> ::std::future::IntoFuture for FluentRequest<'a, CreateSubtaskForTaskRequest> {
36    type Output = httpclient::InMemoryResult<CreateSubtaskForTaskResponse>;
37    type IntoFuture = ::futures::future::BoxFuture<'a, Self::Output>;
38    fn into_future(self) -> Self::IntoFuture {
39        Box::pin(async move {
40            let url = &format!(
41                "/tasks/{task_gid}/subtasks", task_gid = self.params.task_gid
42            );
43            let mut r = self.client.client.post(url);
44            r = r.json(json!({ "data" : self.params.data }));
45            if let Some(ref unwrapped) = self.params.opt_fields {
46                for item in unwrapped {
47                    r = r.query("opt_fields[]", &item.to_string());
48                }
49            }
50            if let Some(ref unwrapped) = self.params.opt_pretty {
51                r = r.query("opt_pretty", &unwrapped.to_string());
52            }
53            r = self.client.authenticate(r);
54            let res = r.await?;
55            res.json().map_err(Into::into)
56        })
57    }
58}