add: polls

This commit is contained in:
trisua 2025-06-04 17:21:46 -04:00
parent 4dfa09207e
commit 6555324650
29 changed files with 339 additions and 56 deletions

View file

@ -1,6 +1,6 @@
use super::*;
use crate::cache::Cache;
use crate::model::communities::PollVote;
use crate::model::communities::{PollOption, PollVote};
use crate::model::moderation::AuditLogEntry;
use crate::model::{Error, Result, auth::User, permissions::FinePermission};
use crate::{auto_method, execute, get, query_row, params};
@ -45,7 +45,7 @@ impl DataManager {
let res = query_row!(
&conn,
"SELECT * FROM pollvotes WHERE id = $1 AND poll_id = $2",
"SELECT * FROM pollvotes WHERE owner = $1 AND poll_id = $2",
&[&(id as i64), &(poll_id as i64)],
|x| { Ok(Self::get_pollvote_from_row(x)) }
);
@ -95,7 +95,7 @@ impl DataManager {
&(data.owner as i64),
&(data.created as i64),
&(data.poll_id as i64),
&(vote_u8 as i64),
&(vote_u8 as i32),
]
);
@ -104,10 +104,20 @@ impl DataManager {
}
// update poll
self.incr_votes_a_count(poll.id).await?;
self.incr_votes_b_count(poll.id).await?;
self.incr_votes_c_count(poll.id).await?;
self.incr_votes_d_count(poll.id).await?;
match data.vote {
PollOption::A => {
self.incr_votes_a_count(poll.id).await?;
}
PollOption::B => {
self.incr_votes_b_count(poll.id).await?;
}
PollOption::C => {
self.incr_votes_c_count(poll.id).await?;
}
PollOption::D => {
self.incr_votes_d_count(poll.id).await?;
}
};
// ...
Ok(data.id)