Skip to content

Commit 7d8a0c5

Browse files
committed
fix: Switch to the Todoist v1 API
1 parent e0533bc commit 7d8a0c5

File tree

8 files changed

+82
-53
lines changed

8 files changed

+82
-53
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ serde = { version = "1.0.219", features = ["alloc", "derive"] }
2828
serde_json = { version = "1.0.149", features = ["alloc"] }
2929
sha2 = "0.10.8"
3030
sha256 = "1.6.0"
31-
todoist-api = "0.3.1"
31+
todoist-api = "1.0.0-alpha.1"
3232
tokio = { version = "1.49.0", features = ["net", "io-std", "rt-multi-thread", "time", "fs", "tracing"] }
3333
tokio-rusqlite = "0.7.0"
3434
toml = "1.0.1"

src/db/sqlite.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,27 @@ const ADVICE_DB_ERROR: &[&str] = &[
1818
const ADVICE_REPORT_DEV: &[&str] =
1919
&["Please report this issue to the development team via GitHub."];
2020

21+
const MIGRATIONS: &[&str] = &[
22+
"CREATE TABLE IF NOT EXISTS kv (
23+
partition TEXT NOT NULL,
24+
key TEXT NOT NULL,
25+
value TEXT NOT NULL,
26+
PRIMARY KEY (partition, key)
27+
)",
28+
"CREATE TABLE IF NOT EXISTS queues (
29+
partition TEXT NOT NULL,
30+
key TEXT NOT NULL,
31+
payload TEXT,
32+
scheduledAt DATETIME DEFAULT CURRENT_TIMESTAMP,
33+
hiddenUntil DATETIME DEFAULT CURRENT_TIMESTAMP,
34+
reservedBy TEXT,
35+
PRIMARY KEY (partition, key)
36+
)",
37+
"CREATE INDEX IF NOT EXISTS idx_queues_partition_hidden ON queues (partition, hiddenUntil)",
38+
"ALTER TABLE queues ADD COLUMN traceparent TEXT",
39+
"ALTER TABLE queues ADD COLUMN tracestate TEXT",
40+
];
41+
2142
impl SqliteDatabase {
2243
pub async fn open(path: &str) -> Result<Self, errors::Error> {
2344
let connection = Connection::open(path).await.wrap_user_err(
@@ -341,27 +362,6 @@ impl Queue for SqliteDatabase {
341362
}
342363
}
343364

344-
const MIGRATIONS: &[&str] = &[
345-
"CREATE TABLE IF NOT EXISTS kv (
346-
partition TEXT NOT NULL,
347-
key TEXT NOT NULL,
348-
value TEXT NOT NULL,
349-
PRIMARY KEY (partition, key)
350-
)",
351-
"CREATE TABLE IF NOT EXISTS queues (
352-
partition TEXT NOT NULL,
353-
key TEXT NOT NULL,
354-
payload TEXT,
355-
scheduledAt DATETIME DEFAULT CURRENT_TIMESTAMP,
356-
hiddenUntil DATETIME DEFAULT CURRENT_TIMESTAMP,
357-
reservedBy TEXT,
358-
PRIMARY KEY (partition, key)
359-
)",
360-
"CREATE INDEX IF NOT EXISTS idx_queues_partition_hidden ON queues (partition, hiddenUntil)",
361-
"ALTER TABLE queues ADD COLUMN traceparent TEXT",
362-
"ALTER TABLE queues ADD COLUMN tracestate TEXT",
363-
];
364-
365365
#[cfg(test)]
366366
mod tests {
367367
use crate::db::QueueMessage;

src/publishers/todoist.rs

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,26 @@ impl TodoistClient {
4747
key,
4848
move || {
4949
Box::pin(async move {
50-
client.get_projects().await.wrap_user_err(
51-
"Failed to fetch Todoist projects.",
52-
&[
53-
"Check that your Todoist API token is valid and has the necessary permissions.",
54-
],
55-
)
50+
let mut projects = Vec::new();
51+
let mut cursor = None;
52+
53+
loop {
54+
let response = client.get_projects(None, cursor).await.wrap_user_err(
55+
"Failed to fetch Todoist projects.",
56+
&[
57+
"Check that your Todoist API token is valid and has the necessary permissions.",
58+
],
59+
)?;
60+
61+
projects.extend(response.results);
62+
cursor = response.next_cursor;
63+
64+
if cursor.is_none() {
65+
break;
66+
}
67+
}
68+
69+
Ok(projects)
5670
})
5771
},
5872
chrono::Duration::hours(24),
@@ -93,12 +107,23 @@ impl TodoistClient {
93107
key,
94108
move || {
95109
Box::pin(async move {
96-
client.get_sections().await.wrap_user_err(
97-
"Failed to fetch Todoist sections.",
98-
&[
99-
"Check that your Todoist API token is valid and has the necessary permissions.",
100-
],
101-
)
110+
let mut sections = Vec::new();
111+
let mut cursor = None;
112+
loop {
113+
let response = client.get_sections(None, cursor).await.wrap_user_err(
114+
"Failed to fetch Todoist sections.",
115+
&[
116+
"Check that your Todoist API token is valid and has the necessary permissions.",
117+
],
118+
)?;
119+
sections.extend(response.results);
120+
cursor = response.next_cursor;
121+
if cursor.is_none() {
122+
break;
123+
}
124+
}
125+
126+
Ok(sections)
102127
})
103128
},
104129
chrono::Duration::hours(24),

src/publishers/todoist_upsert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl Job for TodoistUpsertTask {
7575
],
7676
)?;
7777

78-
if task.is_completed {
78+
if task.completed_at.is_some() {
7979
client.0.reopen_task(&existing_task.id).await.wrap_user_err(
8080
format!("Failed to reopen completed Todoist task '{}'.", job.title),
8181
&[

src/web/admin.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use yew::prelude::*;
2+
3+
use crate::{prelude::*, ui::render_page};
4+
5+
pub async fn admin_index<S: Services>(
6+
_services: actix_web::web::Data<S>,
7+
) -> actix_web::HttpResponse {
8+
render_page("Admin | Automate", || {
9+
html! {
10+
<crate::ui::Center>
11+
<h1>{ "Admin Dashboard" }</h1>
12+
<p>{ "Welcome to the admin dashboard." }</p>
13+
</crate::ui::Center>
14+
}
15+
})
16+
.await
17+
}

src/web/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use human_errors::ResultExt;
33

44
use crate::{filter::Filterable, prelude::Services};
55

6+
mod admin;
67
mod oauth;
78
mod telemetry;
89
mod ui;
@@ -42,7 +43,7 @@ pub async fn run_web_server<S: Services + Clone + Send + Sync + 'static>(
4243
.unwrap_or(false)
4344
})
4445
}))
45-
.to(ui::admin_index::<S>),
46+
.to(admin::admin_index::<S>),
4647
)
4748
.default_service(web::to(ui::not_found))
4849
})

src/web/ui.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use actix_web::HttpResponseBuilder;
22
use yew::{ServerRenderer, prelude::*};
33

4-
use crate::{prelude::*, ui::render_page};
4+
use crate::ui::render_page;
55

66
pub async fn index() -> actix_web::HttpResponse {
77
render_page("Automate | Sierra Softworks", || {
@@ -18,20 +18,6 @@ pub async fn index() -> actix_web::HttpResponse {
1818
}).await
1919
}
2020

21-
pub async fn admin_index<S: Services>(
22-
_services: actix_web::web::Data<S>,
23-
) -> actix_web::HttpResponse {
24-
render_page("Admin | Automate", || {
25-
html! {
26-
<crate::ui::Center>
27-
<h1>{ "Admin Dashboard" }</h1>
28-
<p>{ "Welcome to the admin dashboard." }</p>
29-
</crate::ui::Center>
30-
}
31-
})
32-
.await
33-
}
34-
3521
pub async fn not_found() -> actix_web::HttpResponse {
3622
error_page(
3723
404,

0 commit comments

Comments
 (0)