various todo fixes

This commit is contained in:
jellywx 2021-11-15 08:09:48 +00:00
parent 610779a293
commit c953bc0cd3
2 changed files with 77 additions and 27 deletions

View File

@ -88,15 +88,37 @@ async fn todo(ctx: &Context, invoke: &mut CommandInvoke, args: CommandOptions) {
.await;
}
None => {
let values = sqlx::query!(
// fucking braindead mysql use <=> instead of = for null comparison
let values = if let Some(uid) = keys.0 {
sqlx::query!(
"SELECT todos.id, value FROM todos
INNER JOIN users ON todos.user_id = users.id
WHERE users.user = ?",
uid,
)
.fetch_all(&pool)
.await
.unwrap()
.iter()
.map(|row| (row.id as usize, row.value.clone()))
.collect::<Vec<(usize, String)>>()
} else if let Some(cid) = keys.1 {
sqlx::query!(
"SELECT todos.id, value FROM todos
INNER JOIN channels ON todos.channel_id = channels.id
WHERE channels.channel = ?",
cid,
)
.fetch_all(&pool)
.await
.unwrap()
.iter()
.map(|row| (row.id as usize, row.value.clone()))
.collect::<Vec<(usize, String)>>()
} else {
sqlx::query!(
"SELECT todos.id, value FROM todos
INNER JOIN guilds ON todos.guild_id = guilds.id
WHERE users.user <=> ? AND channels.channel <=> ? AND guilds.guild <=> ?",
keys.0,
keys.1,
WHERE guilds.guild = ?",
keys.2,
)
.fetch_all(&pool)
@ -104,7 +126,8 @@ WHERE users.user <=> ? AND channels.channel <=> ? AND guilds.guild <=> ?",
.unwrap()
.iter()
.map(|row| (row.id as usize, row.value.clone()))
.collect::<Vec<(usize, String)>>();
.collect::<Vec<(usize, String)>>()
};
let resp = show_todo_page(&values, 0, keys.0, keys.1, keys.2);

View File

@ -164,11 +164,37 @@ impl ComponentDataModel {
if Some(component.user.id.0) == pager.user_id || pager.user_id.is_none() {
let pool = ctx.data.read().await.get::<SQLPool>().cloned().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 <=> ?",
pager.user_id,
pager.channel_id,
let values = if let Some(uid) = pager.user_id {
sqlx::query!(
"SELECT todos.id, value FROM todos
INNER JOIN users ON todos.user_id = users.id
WHERE users.user = ?",
uid,
)
.fetch_all(&pool)
.await
.unwrap()
.iter()
.map(|row| (row.id as usize, row.value.clone()))
.collect::<Vec<(usize, String)>>()
} else if let Some(cid) = pager.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(&pool)
.await
.unwrap()
.iter()
.map(|row| (row.id as usize, row.value.clone()))
.collect::<Vec<(usize, String)>>()
} else {
sqlx::query!(
"SELECT todos.id, value FROM todos
INNER JOIN guilds ON todos.guild_id = guilds.id
WHERE guilds.guild = ?",
pager.guild_id,
)
.fetch_all(&pool)
@ -176,7 +202,8 @@ impl ComponentDataModel {
.unwrap()
.iter()
.map(|row| (row.id as usize, row.value.clone()))
.collect::<Vec<(usize, String)>>();
.collect::<Vec<(usize, String)>>()
};
let max_pages = max_todo_page(&values);