feat: Enhance governance proposal model with activity tracking

- Add `Activity` model to track proposal creation and voting.
- Include `ActivityType` enum for different activity types.
- Improve `Proposal` model to record voting with comments.
- Refactor `models/governance` module for better organization.
This commit is contained in:
Mahmoud-Emad
2025-05-27 20:47:34 +03:00
parent 2a2d69dafb
commit 972d0982b0
4 changed files with 197 additions and 54 deletions

View File

@@ -2,7 +2,7 @@
use chrono::{Duration, Utc};
use heromodels::db::{Collection, Db};
use heromodels::models::governance::{Ballot, Proposal, ProposalStatus, VoteEventStatus};
use heromodels::models::governance::{Proposal, ProposalStatus, VoteEventStatus};
fn main() {
println!("Governance Proposal Model Example\n");
@@ -101,23 +101,23 @@ fn main() {
// Example of voting with comments using the cast_vote_with_comment method
println!("Adding votes with comments...");
// User 7 votes for 'Approve Allocation' with a comment
proposal = proposal.cast_vote_with_comment(
Some(110), // ballot_id
7, // user_id
1, // chosen_option_id (Approve Allocation)
80, // shares
"I strongly support this proposal because it aligns with our community values."
7, // user_id
1, // chosen_option_id (Approve Allocation)
80, // shares
"I strongly support this proposal because it aligns with our community values.",
);
// User 8 votes for 'Reject Allocation' with a comment
proposal = proposal.cast_vote_with_comment(
Some(111), // ballot_id
8, // user_id
2, // chosen_option_id (Reject Allocation)
60, // shares
"I have concerns about the allocation priorities."
8, // user_id
2, // chosen_option_id (Reject Allocation)
60, // shares
"I have concerns about the allocation priorities.",
);
println!("\nBallots with Comments:");
@@ -218,34 +218,34 @@ fn main() {
// Example of voting with comments on a private proposal
println!("\nAdding votes with comments to private proposal...");
// User 20 (eligible) votes with a comment
private_proposal = private_proposal.cast_vote_with_comment(
Some(202), // ballot_id
20, // user_id (eligible)
1, // chosen_option_id
75, // shares
"I support this restructuring plan with some reservations."
Some(202), // ballot_id
20, // user_id (eligible)
1, // chosen_option_id
75, // shares
"I support this restructuring plan with some reservations.",
);
// User 30 (eligible) votes with a comment
private_proposal = private_proposal.cast_vote_with_comment(
Some(203), // ballot_id
30, // user_id (eligible)
2, // chosen_option_id
90, // shares
"I believe we should reconsider the timing of these changes."
Some(203), // ballot_id
30, // user_id (eligible)
2, // chosen_option_id
90, // shares
"I believe we should reconsider the timing of these changes.",
);
// User 40 (ineligible) tries to vote with a comment
private_proposal = private_proposal.cast_vote_with_comment(
Some(204), // ballot_id
40, // user_id (ineligible)
1, // chosen_option_id
50, // shares
"This restructuring seems unnecessary."
Some(204), // ballot_id
40, // user_id (ineligible)
1, // chosen_option_id
50, // shares
"This restructuring seems unnecessary.",
);
println!("Eligible users 20 and 30 added votes with comments.");
println!("Ineligible user 40 attempted to vote with a comment (should be rejected).");