1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// Generated by basecamp-sdk-generator from openapi.json and behavior-model.json. DO NOT EDIT.
//! Todos operations.
#![allow(
clippy::too_many_arguments,
clippy::wildcard_imports,
clippy::doc_markdown
)]
use crate::client::AccountClient;
use crate::error::Error;
use crate::generated::routes;
#[allow(unused_imports)]
use crate::generated::types::*;
use crate::pagination::Page;
/// Optional query parameters for `ListTodos`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct ListTodosParams {
/// active|archived|trashed
pub status: Option<String>,
/// `completed`.
pub completed: Option<bool>,
/// Page number for paginating through results. Defaults to 1. A positive value selects exactly that page, not a starting offset; see SPEC section 8.
pub page: Option<i32>,
}
/// `Todos` operations, sent through one [`AccountClient`].
#[derive(Debug, Clone, Copy)]
pub struct TodosService<'a> {
client: &'a AccountClient,
}
impl<'a> TodosService<'a> {
pub(crate) fn new(client: &'a AccountClient) -> Self {
Self { client }
}
/// The client this service sends through.
pub fn client(&self) -> &'a AccountClient {
self.client
}
/// Mark a todo as complete
///
/// `POST /todos/{todoId}/completion.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
pub async fn complete(&self, todo_id: i64) -> Result<(), Error> {
let operation = self.client.operation(&routes::COMPLETE_TODO, &[&todo_id]);
self.client.send_unit(operation).await
}
/// Create a new todo in a todolist
///
/// `POST /todolists/{todolistId}/todos.json` — not idempotent, sent exactly once.
pub async fn create(
&self,
todolist_id: i64,
body: &CreateTodoRequestContent,
) -> Result<CreateTodoResponseContent, Error> {
let mut operation = self.client.operation(&routes::CREATE_TODO, &[&todolist_id]);
operation.json(body)?;
self.client.send(operation).await
}
/// Create a to-do directly under a project's to-do set, outside any to-do list.
/// This form exists only project-scoped (no account-scoped variant); parameters
/// and response match the to-do-list create. Find a project's to-do set id via
/// GetTodoset.
///
/// `POST /buckets/{bucketId}/todosets/{todosetId}/todos.json` — not idempotent, sent exactly once.
pub async fn create_todoset_todo(
&self,
bucket_id: i64,
todoset_id: i64,
body: &CreateTodosetTodoRequestContent,
) -> Result<CreateTodosetTodoResponseContent, Error> {
let mut operation = self
.client
.operation(&routes::CREATE_TODOSET_TODO, &[&bucket_id, &todoset_id]);
operation.json(body)?;
self.client.send(operation).await
}
/// Get a single todo by id
///
/// `GET /todos/{todoId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
pub async fn get(&self, todo_id: i64) -> Result<GetTodoResponseContent, Error> {
let operation = self.client.operation(&routes::GET_TODO, &[&todo_id]);
self.client.send(operation).await
}
/// List todos in a todolist
///
/// **Pagination**: Uses Link header (RFC5988). Follow the `next` rel URL
/// to fetch additional pages. X-Total-Count header provides total count.
///
/// `GET /todolists/{todolistId}/todos.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
pub async fn list(
&self,
todolist_id: i64,
params: &ListTodosParams,
) -> Result<Page<ListTodosResponseContent>, Error> {
let mut operation = self.client.operation(&routes::LIST_TODOS, &[&todolist_id]);
operation.query_optional("status", params.status.as_ref());
operation.query_optional("completed", params.completed.as_ref());
operation.query_optional("page", params.page.as_ref());
self.client.send_page(operation).await
}
/// Replace a todo with a new complete representation.
/// The request body is the todo's full writable state: any writable field
/// omitted from the request is cleared server-side (empty/missing
/// assignee_ids clears assignees, missing description clears it, and so
/// on). content is required — a request without it is rejected.
/// To set some fields while preserving the rest, use the SDK's merge-safe
/// update or edit methods, which GET the current todo and PUT the full
/// representation back. Those read-modify-write helpers are not atomic:
/// a concurrent write between the GET and PUT is overwritten (last write
/// wins for the whole representation; the window is one round-trip).
///
/// `PUT /todos/{todoId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
pub async fn replace(
&self,
todo_id: i64,
body: &ReplaceTodoRequestContent,
) -> Result<ReplaceTodoResponseContent, Error> {
let mut operation = self.client.operation(&routes::REPLACE_TODO, &[&todo_id]);
operation.json(body)?;
self.client.send(operation).await
}
/// Reposition a todo within its todolist, or move it into another list or the to-do set in the same project.
///
/// `parent_id` names a to-do list, or the project's to-do set, to move the todo
/// into; the todo keeps its id. It must be in the same project: anything else
/// answers 422. To move a todo into a list in another project, use
/// MoveRecording.
///
/// `PUT /todos/{todoId}/position.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
pub async fn reposition(
&self,
todo_id: i64,
body: &RepositionTodoRequestContent,
) -> Result<(), Error> {
let mut operation = self.client.operation(&routes::REPOSITION_TODO, &[&todo_id]);
operation.json(body)?;
self.client.send_unit(operation).await
}
/// Mark a todo as incomplete
///
/// `DELETE /todos/{todoId}/completion.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
pub async fn uncomplete(&self, todo_id: i64) -> Result<(), Error> {
let operation = self.client.operation(&routes::UNCOMPLETE_TODO, &[&todo_id]);
self.client.send_unit(operation).await
}
}