From ef10902c1e2e8cccdc35aa30e62d451e95cb942a Mon Sep 17 00:00:00 2001 From: jude Date: Fri, 3 May 2024 16:21:27 +0100 Subject: [PATCH] Fix todo list deletion not working properly --- src/component_models/mod.rs | 59 ++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/src/component_models/mod.rs b/src/component_models/mod.rs index 0164b53..2c3235c 100644 --- a/src/component_models/mod.rs +++ b/src/component_models/mod.rs @@ -282,21 +282,52 @@ impl ComponentDataModel { .await .unwrap(); - let values = sqlx::query!( - // fucking braindead mysql use <=> instead of = for null comparison - " - SELECT id, value FROM todos WHERE user_id <=> ? AND channel_id <=> ? AND guild_id <=> ? + let values = if let Some(uid) = selector.user_id { + sqlx::query!( + " + SELECT todos.id, value FROM todos + INNER JOIN users ON todos.user_id = users.id + WHERE users.user = ? ", - selector.user_id, - selector.channel_id, - selector.guild_id, - ) - .fetch_all(&data.database) - .await - .unwrap() - .iter() - .map(|row| (row.id as usize, row.value.clone())) - .collect::>(); + uid, + ) + .fetch_all(&data.database) + .await + .unwrap() + .iter() + .map(|row| (row.id as usize, row.value.clone())) + .collect::>() + } else if let Some(cid) = selector.channel_id { + sqlx::query!( + " + SELECT todos.id, value FROM todos + INNER JOIN channels ON todos.channel_id = channels.id + WHERE channels.channel = ? + ", + cid, + ) + .fetch_all(&data.database) + .await + .unwrap() + .iter() + .map(|row| (row.id as usize, row.value.clone())) + .collect::>() + } else { + sqlx::query!( + " + SELECT todos.id, value FROM todos + INNER JOIN guilds ON todos.guild_id = guilds.id + WHERE guilds.guild = ? + ", + selector.guild_id, + ) + .fetch_all(&data.database) + .await + .unwrap() + .iter() + .map(|row| (row.id as usize, row.value.clone())) + .collect::>() + }; let resp = show_todo_page( &values,