Skip to content

Commit c238c61

Browse files
committed
refactor(db): add db logic for reminder_optouts feature
1 parent f021627 commit c238c61

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

crates/rustmail/src/db/operations/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub mod features;
33
pub mod init;
44
pub mod logs;
55
pub mod messages;
6+
pub mod reminder_optouts;
67
pub mod reminders;
78
pub mod scheduled;
89
pub mod snippets;
@@ -14,6 +15,7 @@ pub use features::*;
1415
pub use init::*;
1516
pub use logs::*;
1617
pub use messages::*;
18+
pub use reminder_optouts::*;
1719
pub use reminders::*;
1820
pub use scheduled::*;
1921
pub use snippets::*;

crates/rustmail/src/db/operations/reminders.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub struct Reminder {
1010
pub trigger_time: i64,
1111
pub created_at: i64,
1212
pub completed: bool,
13+
pub target_roles: Option<String>,
1314
}
1415

1516
pub async fn insert_reminder(reminder: &Reminder, pool: &sqlx::SqlitePool) -> ModmailResult<i64> {
@@ -35,8 +36,8 @@ pub async fn insert_reminder(reminder: &Reminder, pool: &sqlx::SqlitePool) -> Mo
3536

3637
let result = sqlx::query!(
3738
r#"
38-
INSERT INTO reminders (thread_id, user_id, channel_id, guild_id, reminder_content, trigger_time, created_at, completed)
39-
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
39+
INSERT INTO reminders (thread_id, user_id, channel_id, guild_id, reminder_content, trigger_time, created_at, completed, target_roles)
40+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
4041
"#,
4142
reminder.thread_id,
4243
user_id,
@@ -45,7 +46,8 @@ pub async fn insert_reminder(reminder: &Reminder, pool: &sqlx::SqlitePool) -> Mo
4546
reminder.reminder_content,
4647
reminder.trigger_time,
4748
reminder.created_at,
48-
reminder.completed
49+
reminder.completed,
50+
reminder.target_roles
4951
)
5052
.execute(pool)
5153
.await?;
@@ -79,7 +81,7 @@ pub async fn get_all_pending_reminders(
7981
let rows = sqlx::query_as!(
8082
Reminder,
8183
r#"
82-
SELECT thread_id, user_id, channel_id, guild_id, reminder_content, trigger_time, created_at, completed
84+
SELECT thread_id, user_id, channel_id, guild_id, reminder_content, trigger_time, created_at, completed, target_roles
8385
FROM reminders
8486
WHERE completed = FALSE
8587
ORDER BY trigger_time ASC
@@ -97,7 +99,7 @@ pub async fn get_reminder_by_id(
9799
let row = sqlx::query_as!(
98100
Reminder,
99101
r#"
100-
SELECT thread_id, user_id, channel_id, guild_id, reminder_content, trigger_time, created_at, completed
102+
SELECT thread_id, user_id, channel_id, guild_id, reminder_content, trigger_time, created_at, completed, target_roles
101103
FROM reminders
102104
WHERE id = ?
103105
"#,

0 commit comments

Comments
 (0)