feat: Added optional vote comment to the proposal vote fields
This commit is contained in:
parent
bd3c0c1932
commit
bebb35e686
@ -39,9 +39,9 @@ fn main() {
|
||||
);
|
||||
|
||||
// Add vote options
|
||||
proposal = proposal.add_option(1, "Approve Allocation");
|
||||
proposal = proposal.add_option(2, "Reject Allocation");
|
||||
proposal = proposal.add_option(3, "Abstain");
|
||||
proposal = proposal.add_option(1, "Approve Allocation", Some("This is the approval option"));
|
||||
proposal = proposal.add_option(2, "Reject Allocation", Some("This is the rejection option"));
|
||||
proposal = proposal.add_option(3, "Abstain", Some("This is the abstain option"));
|
||||
|
||||
println!("Added Vote Options:");
|
||||
for option in &proposal.options {
|
||||
@ -139,8 +139,16 @@ fn main() {
|
||||
Utc::now() + Duration::days(7),
|
||||
);
|
||||
private_proposal.private_group = Some(vec![10, 20, 30]); // Only users 10, 20, 30 can vote
|
||||
private_proposal = private_proposal.add_option(1, "Accept Restructure");
|
||||
private_proposal = private_proposal.add_option(2, "Reject Restructure");
|
||||
private_proposal = private_proposal.add_option(
|
||||
1,
|
||||
"Accept Restructure",
|
||||
Some("This is the accept restructure option".to_string()),
|
||||
);
|
||||
private_proposal = private_proposal.add_option(
|
||||
2,
|
||||
"Reject Restructure",
|
||||
Some("This is the reject restructure option".to_string()),
|
||||
);
|
||||
|
||||
println!(
|
||||
"\nBefore saving - Created Private Proposal: '{}'",
|
||||
|
@ -48,7 +48,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
);
|
||||
|
||||
engine.register_fn("create_vote_option", |id: i64, text: String| {
|
||||
VoteOption::new(id as u8, text)
|
||||
VoteOption::new(id as u8, text, Some("This is an optional comment"))
|
||||
});
|
||||
|
||||
engine.register_fn(
|
||||
@ -93,7 +93,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
engine.register_fn(
|
||||
"add_option_to_proposal",
|
||||
|mut proposal: Proposal, option_id: i64, option_text: String| -> Proposal {
|
||||
proposal.add_option(option_id as u8, option_text)
|
||||
proposal.add_option(
|
||||
option_id as u8,
|
||||
option_text,
|
||||
Some("This is an optional comment".to_string()),
|
||||
)
|
||||
},
|
||||
);
|
||||
|
||||
@ -229,7 +233,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
if index >= 0 && index < proposal.options.len() as i64 {
|
||||
proposal.options[index as usize].clone()
|
||||
} else {
|
||||
VoteOption::new(0, "Invalid Option")
|
||||
VoteOption::new(
|
||||
0,
|
||||
"Invalid Option",
|
||||
Some("This is an invalid option".to_string()),
|
||||
)
|
||||
}
|
||||
},
|
||||
);
|
||||
|
@ -45,19 +45,21 @@ impl Default for VoteEventStatus {
|
||||
/// VoteOption represents a specific choice that can be voted on
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, CustomType)]
|
||||
pub struct VoteOption {
|
||||
pub id: u8, // Simple identifier for this option
|
||||
pub text: String, // Descriptive text of the option
|
||||
pub count: i64, // How many votes this option has received
|
||||
pub min_valid: Option<i64>, // Optional: minimum votes needed
|
||||
pub id: u8, // Simple identifier for this option
|
||||
pub text: String, // Descriptive text of the option
|
||||
pub count: i64, // How many votes this option has received
|
||||
pub min_valid: Option<i64>, // Optional: minimum votes needed,
|
||||
pub comment: Option<String>, // Optional: comment
|
||||
}
|
||||
|
||||
impl VoteOption {
|
||||
pub fn new(id: u8, text: impl ToString) -> Self {
|
||||
pub fn new(id: u8, text: impl ToString, comment: Option<impl ToString>) -> Self {
|
||||
Self {
|
||||
id,
|
||||
text: text.to_string(),
|
||||
count: 0,
|
||||
min_valid: None,
|
||||
comment: comment.map(|c| c.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -166,8 +168,13 @@ impl Proposal {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_option(mut self, option_id: u8, option_text: impl ToString) -> Self {
|
||||
let new_option = VoteOption::new(option_id, option_text);
|
||||
pub fn add_option(
|
||||
mut self,
|
||||
option_id: u8,
|
||||
option_text: impl ToString,
|
||||
comment: Option<impl ToString>,
|
||||
) -> Self {
|
||||
let new_option = VoteOption::new(option_id, option_text, comment);
|
||||
self.options.push(new_option);
|
||||
self
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user