feat: Support incremental mode:

- Support incremental mode in heromodels
- Updated the example to refelct the changes
- Updated the tests to reflect the changes
This commit is contained in:
Mahmoud Emad
2025-05-17 11:12:09 +03:00
parent bd4770b99b
commit bde5db0e52
16 changed files with 1074 additions and 136 deletions

View File

@@ -140,7 +140,11 @@ pub struct Calendar {
impl Calendar {
/// Creates a new calendar
pub fn new(id: u32, name: impl ToString) -> Self {
///
/// # Arguments
/// * `id` - Optional ID for the calendar. If None, the ID will be auto-generated.
/// * `name` - Name of the calendar
pub fn new(id: Option<u32>, name: impl ToString) -> Self {
Self {
base_data: BaseModelData::new(id),
name: name.to_string(),

View File

@@ -14,7 +14,10 @@ pub struct Comment {
impl Comment {
/// Create a new comment
pub fn new(id: u32) -> Self {
///
/// # Arguments
/// * `id` - Optional ID for the comment. If None, the ID will be auto-generated.
pub fn new(id: Option<u32>) -> Self {
Self {
base_data: BaseModelData::new(id),
user_id: 0,

View File

@@ -22,13 +22,22 @@ pub struct Account {
impl Account {
/// Create a new account
///
/// # Arguments
/// * `id` - Optional ID for the account. If None, the ID will be auto-generated.
/// * `name` - Name of the account
/// * `user_id` - ID of the user who owns the account
/// * `description` - Description of the account
/// * `ledger` - Ledger/blockchain where the account is located
/// * `address` - Address of the account on the blockchain
/// * `pubkey` - Public key
pub fn new(
id: u32,
name: impl ToString,
user_id: u32,
description: impl ToString,
ledger: impl ToString,
address: impl ToString,
id: Option<u32>,
name: impl ToString,
user_id: u32,
description: impl ToString,
ledger: impl ToString,
address: impl ToString,
pubkey: impl ToString
) -> Self {
Self {

View File

@@ -35,7 +35,7 @@ pub struct Asset {
impl Asset {
/// Create a new asset
pub fn new(
id: u32,
id: Option<u32>,
name: impl ToString,
description: impl ToString,
amount: f64,

View File

@@ -113,7 +113,7 @@ pub struct Listing {
impl Listing {
/// Create a new listing
pub fn new(
id: u32,
id: Option<u32>,
title: impl ToString,
description: impl ToString,
asset_id: impl ToString,

View File

@@ -75,7 +75,14 @@ pub struct Ballot {
}
impl Ballot {
pub fn new(id: u32, user_id: u32, vote_option_id: u8, shares_count: i64) -> Self {
/// Create a new ballot
///
/// # 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 {
Self {
base_data: BaseModelData::new(id),
user_id,
@@ -107,7 +114,16 @@ pub struct Proposal {
}
impl Proposal {
pub fn new(id: u32, creator_id: impl ToString, title: impl ToString, description: impl ToString, vote_start_date: DateTime<Utc>, vote_end_date: DateTime<Utc>) -> Self {
/// Create a new proposal
///
/// # 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 {
Self {
base_data: BaseModelData::new(id),
creator_id: creator_id.to_string(),
@@ -128,8 +144,8 @@ impl Proposal {
self.options.push(new_option);
self
}
pub fn cast_vote(mut self, ballot_id: u32, user_id: u32, chosen_option_id: u8, shares: i64) -> Self {
pub fn cast_vote(mut self, ballot_id: Option<u32>, 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;

View File

@@ -27,7 +27,10 @@ pub struct User {
impl User {
/// Create a new user
pub fn new(id: u32) -> Self {
///
/// # Arguments
/// * `id` - Optional ID for the user. If None, the ID will be auto-generated.
pub fn new(id: Option<u32>) -> Self {
Self {
base_data: BaseModelData::new(id),
username: String::new(),