Skip to main content

lib_client_asana/
types.rs

1use serde::{Deserialize, Serialize};
2
3/// Asana API response wrapper.
4#[derive(Debug, Clone, Deserialize)]
5pub struct AsanaResponse<T> {
6    pub data: T,
7}
8
9/// Task.
10#[derive(Debug, Clone, Deserialize)]
11pub struct Task {
12    pub gid: String,
13    pub name: String,
14    pub notes: Option<String>,
15    pub completed: bool,
16    pub completed_at: Option<String>,
17    pub due_on: Option<String>,
18    pub due_at: Option<String>,
19    pub assignee: Option<User>,
20    pub projects: Option<Vec<Project>>,
21    pub tags: Option<Vec<Tag>>,
22    pub created_at: String,
23    pub modified_at: String,
24    pub permalink_url: Option<String>,
25}
26
27/// Project.
28#[derive(Debug, Clone, Deserialize)]
29pub struct Project {
30    pub gid: String,
31    pub name: String,
32    pub notes: Option<String>,
33    pub color: Option<String>,
34    pub archived: Option<bool>,
35    pub workspace: Option<Workspace>,
36    pub team: Option<Team>,
37    pub created_at: Option<String>,
38    pub modified_at: Option<String>,
39    pub permalink_url: Option<String>,
40}
41
42/// Workspace.
43#[derive(Debug, Clone, Deserialize)]
44pub struct Workspace {
45    pub gid: String,
46    pub name: String,
47}
48
49/// Team.
50#[derive(Debug, Clone, Deserialize)]
51pub struct Team {
52    pub gid: String,
53    pub name: String,
54}
55
56/// Section.
57#[derive(Debug, Clone, Deserialize)]
58pub struct Section {
59    pub gid: String,
60    pub name: String,
61    pub project: Option<Project>,
62}
63
64/// User.
65#[derive(Debug, Clone, Deserialize)]
66pub struct User {
67    pub gid: String,
68    pub name: String,
69    pub email: Option<String>,
70}
71
72/// Tag.
73#[derive(Debug, Clone, Deserialize)]
74pub struct Tag {
75    pub gid: String,
76    pub name: String,
77    pub color: Option<String>,
78}
79
80/// Task list response.
81#[derive(Debug, Clone, Deserialize)]
82pub struct TaskList {
83    pub data: Vec<Task>,
84    pub next_page: Option<NextPage>,
85}
86
87/// Next page info.
88#[derive(Debug, Clone, Deserialize)]
89pub struct NextPage {
90    pub offset: String,
91    pub uri: String,
92}
93
94/// Create task input.
95#[derive(Debug, Clone, Default, Serialize)]
96pub struct CreateTaskInput {
97    pub name: String,
98    #[serde(skip_serializing_if = "Option::is_none")]
99    pub notes: Option<String>,
100    #[serde(skip_serializing_if = "Option::is_none")]
101    pub workspace: Option<String>,
102    #[serde(skip_serializing_if = "Option::is_none")]
103    pub projects: Option<Vec<String>>,
104    #[serde(skip_serializing_if = "Option::is_none")]
105    pub assignee: Option<String>,
106    #[serde(skip_serializing_if = "Option::is_none")]
107    pub due_on: Option<String>,
108    #[serde(skip_serializing_if = "Option::is_none")]
109    pub due_at: Option<String>,
110    #[serde(skip_serializing_if = "Option::is_none")]
111    pub tags: Option<Vec<String>>,
112}
113
114impl CreateTaskInput {
115    pub fn new(name: impl Into<String>) -> Self {
116        Self {
117            name: name.into(),
118            ..Default::default()
119        }
120    }
121
122    pub fn notes(mut self, notes: impl Into<String>) -> Self {
123        self.notes = Some(notes.into());
124        self
125    }
126
127    pub fn workspace(mut self, gid: impl Into<String>) -> Self {
128        self.workspace = Some(gid.into());
129        self
130    }
131
132    pub fn project(mut self, gid: impl Into<String>) -> Self {
133        self.projects = Some(vec![gid.into()]);
134        self
135    }
136
137    pub fn assignee(mut self, gid: impl Into<String>) -> Self {
138        self.assignee = Some(gid.into());
139        self
140    }
141
142    pub fn due_on(mut self, date: impl Into<String>) -> Self {
143        self.due_on = Some(date.into());
144        self
145    }
146}
147
148/// Update task input.
149#[derive(Debug, Clone, Default, Serialize)]
150pub struct UpdateTaskInput {
151    #[serde(skip_serializing_if = "Option::is_none")]
152    pub name: Option<String>,
153    #[serde(skip_serializing_if = "Option::is_none")]
154    pub notes: Option<String>,
155    #[serde(skip_serializing_if = "Option::is_none")]
156    pub completed: Option<bool>,
157    #[serde(skip_serializing_if = "Option::is_none")]
158    pub assignee: Option<String>,
159    #[serde(skip_serializing_if = "Option::is_none")]
160    pub due_on: Option<String>,
161    #[serde(skip_serializing_if = "Option::is_none")]
162    pub due_at: Option<String>,
163}
164
165impl UpdateTaskInput {
166    pub fn new() -> Self {
167        Self::default()
168    }
169
170    pub fn name(mut self, name: impl Into<String>) -> Self {
171        self.name = Some(name.into());
172        self
173    }
174
175    pub fn notes(mut self, notes: impl Into<String>) -> Self {
176        self.notes = Some(notes.into());
177        self
178    }
179
180    pub fn completed(mut self, completed: bool) -> Self {
181        self.completed = Some(completed);
182        self
183    }
184
185    pub fn assignee(mut self, gid: impl Into<String>) -> Self {
186        self.assignee = Some(gid.into());
187        self
188    }
189
190    pub fn due_on(mut self, date: impl Into<String>) -> Self {
191        self.due_on = Some(date.into());
192        self
193    }
194}
195
196/// Add to project input.
197#[derive(Debug, Clone, Serialize)]
198pub struct AddToProjectInput {
199    pub project: String,
200    #[serde(skip_serializing_if = "Option::is_none")]
201    pub section: Option<String>,
202}
203
204impl AddToProjectInput {
205    pub fn new(project_gid: impl Into<String>) -> Self {
206        Self {
207            project: project_gid.into(),
208            section: None,
209        }
210    }
211
212    pub fn section(mut self, section_gid: impl Into<String>) -> Self {
213        self.section = Some(section_gid.into());
214        self
215    }
216}