fmt, fixes and additions
This commit is contained in:
@@ -4,5 +4,5 @@ pub mod proposal;
|
||||
|
||||
pub mod attached_file;
|
||||
|
||||
pub use self::proposal::{Proposal, Ballot, VoteOption, ProposalStatus, VoteEventStatus};
|
||||
pub use self::attached_file::AttachedFile;
|
||||
pub use self::attached_file::AttachedFile;
|
||||
pub use self::proposal::{Ballot, Proposal, ProposalStatus, VoteEventStatus, VoteOption};
|
||||
|
@@ -5,9 +5,9 @@ use heromodels_derive::model; // For #[model]
|
||||
use rhai::{CustomType, TypeBuilder};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use heromodels_core::BaseModelData;
|
||||
use crate::models::core::Comment;
|
||||
use super::AttachedFile;
|
||||
use crate::models::core::Comment;
|
||||
use heromodels_core::BaseModelData;
|
||||
|
||||
// --- Enums ---
|
||||
|
||||
@@ -72,9 +72,9 @@ impl VoteOption {
|
||||
#[model] // Has base.Base in V spec
|
||||
pub struct Ballot {
|
||||
pub base_data: BaseModelData,
|
||||
pub user_id: u32, // The ID of the user who cast this ballot
|
||||
pub vote_option_id: u8, // The 'id' of the VoteOption chosen
|
||||
pub shares_count: i64, // Number of shares/tokens/voting power
|
||||
pub user_id: u32, // The ID of the user who cast this ballot
|
||||
pub vote_option_id: u8, // The 'id' of the VoteOption chosen
|
||||
pub shares_count: i64, // Number of shares/tokens/voting power
|
||||
pub comment: Option<String>, // Optional comment from the voter
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ impl Proposal {
|
||||
eprintln!("Voting is not open for proposal '{}'", self.title);
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
// Check if the option exists
|
||||
if !self.options.iter().any(|opt| opt.id == chosen_option_id) {
|
||||
eprintln!(
|
||||
@@ -290,7 +290,7 @@ impl Proposal {
|
||||
);
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
// Check eligibility for private proposals
|
||||
if let Some(group) = &self.private_group {
|
||||
if !group.contains(&user_id) {
|
||||
@@ -301,14 +301,14 @@ impl Proposal {
|
||||
return self;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Create a new ballot with the comment
|
||||
let mut new_ballot = Ballot::new(ballot_id, user_id, chosen_option_id, shares);
|
||||
new_ballot.comment = Some(comment.to_string());
|
||||
|
||||
|
||||
// Add the ballot to the proposal
|
||||
self.ballots.push(new_ballot);
|
||||
|
||||
|
||||
// Update the vote count for the chosen option
|
||||
if let Some(option) = self
|
||||
.options
|
||||
@@ -317,7 +317,7 @@ impl Proposal {
|
||||
{
|
||||
option.count += shares;
|
||||
}
|
||||
|
||||
|
||||
self
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user