fix: Use incremental ID
This commit is contained in:
@@ -75,16 +75,15 @@ pub struct Ballot {
|
||||
}
|
||||
|
||||
impl Ballot {
|
||||
/// Create a new ballot
|
||||
/// Create a new ballot with auto-generated ID
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `id` - Optional ID for the ballot. If None, the ID will be auto-generated.
|
||||
/// * `user_id` - ID of the user who cast this ballot
|
||||
/// * `vote_option_id` - ID of the vote option chosen
|
||||
/// * `shares_count` - Number of shares/tokens/voting power
|
||||
pub fn new(id: Option<u32>, user_id: u32, vote_option_id: u8, shares_count: i64) -> Self {
|
||||
pub fn new(user_id: u32, vote_option_id: u8, shares_count: i64) -> Self {
|
||||
Self {
|
||||
base_data: BaseModelData::new(id),
|
||||
base_data: BaseModelData::new(),
|
||||
user_id,
|
||||
vote_option_id,
|
||||
shares_count,
|
||||
@@ -114,18 +113,17 @@ pub struct Proposal {
|
||||
}
|
||||
|
||||
impl Proposal {
|
||||
/// Create a new proposal
|
||||
/// Create a new proposal with auto-generated ID
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `id` - Optional ID for the proposal. If None, the ID will be auto-generated.
|
||||
/// * `creator_id` - ID of the user who created the proposal
|
||||
/// * `title` - Title of the proposal
|
||||
/// * `description` - Description of the proposal
|
||||
/// * `vote_start_date` - Date when voting starts
|
||||
/// * `vote_end_date` - Date when voting ends
|
||||
pub fn new(id: Option<u32>, creator_id: impl ToString, title: impl ToString, description: impl ToString, vote_start_date: DateTime<Utc>, vote_end_date: DateTime<Utc>) -> Self {
|
||||
pub fn new(creator_id: impl ToString, title: impl ToString, description: impl ToString, vote_start_date: DateTime<Utc>, vote_end_date: DateTime<Utc>) -> Self {
|
||||
Self {
|
||||
base_data: BaseModelData::new(id),
|
||||
base_data: BaseModelData::new(),
|
||||
creator_id: creator_id.to_string(),
|
||||
title: title.to_string(),
|
||||
description: description.to_string(),
|
||||
@@ -145,7 +143,7 @@ impl Proposal {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn cast_vote(mut self, ballot_id: Option<u32>, user_id: u32, chosen_option_id: u8, shares: i64) -> Self {
|
||||
pub fn cast_vote(mut self, user_id: u32, chosen_option_id: u8, shares: i64) -> Self {
|
||||
if self.vote_status != VoteEventStatus::Open {
|
||||
eprintln!("Voting is not open for proposal '{}'", self.title);
|
||||
return self;
|
||||
@@ -161,7 +159,7 @@ impl Proposal {
|
||||
}
|
||||
}
|
||||
|
||||
let new_ballot = Ballot::new(ballot_id, user_id, chosen_option_id, shares);
|
||||
let new_ballot = Ballot::new(user_id, chosen_option_id, shares);
|
||||
self.ballots.push(new_ballot);
|
||||
|
||||
if let Some(option) = self.options.iter_mut().find(|opt| opt.id == chosen_option_id) {
|
||||
|
Reference in New Issue
Block a user