diff --git a/herodb/src/models/circle/circle.rs b/herodb/src/models/circle/circle.rs index a8d521d..62e1995 100644 --- a/herodb/src/models/circle/circle.rs +++ b/herodb/src/models/circle/circle.rs @@ -2,33 +2,12 @@ use serde::{Deserialize, Serialize}; use crate::db::{SledModel, Storable}; use std::collections::HashMap; -/// Role represents the role of a member in a circle -#[derive(Debug, Clone, Serialize, Deserialize)] -pub enum Role { - Admin, - Stakeholder, - Member, - Contributor, - Guest, -} - -/// Member represents a member of a circle -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Member { - pub pubkeys: Vec, // public keys of the member - pub emails: Vec, // list of emails - pub name: String, // name of the member - pub description: String, // optional description - pub role: Role, // role of the member in the circle -} - /// Circle represents a collection of members (users or other circles) #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Circle { pub id: u32, // unique id pub name: String, // name of the circle pub description: String, // optional description - pub members: Vec, // members of the circle } impl Circle { @@ -38,15 +17,9 @@ impl Circle { id, name, description, - members: Vec::new(), } } - /// Add a member to the circle - pub fn add_member(&mut self, member: Member) { - self.members.push(member); - } - /// Returns a map of index keys for this circle pub fn index_keys(&self) -> HashMap { let mut keys = HashMap::new(); diff --git a/herodb/src/models/circle/member.rs b/herodb/src/models/circle/member.rs new file mode 100644 index 0000000..c39fa1f --- /dev/null +++ b/herodb/src/models/circle/member.rs @@ -0,0 +1,82 @@ +use serde::{Deserialize, Serialize}; +use crate::db::{SledModel, Storable}; +use std::collections::HashMap; + +/// Role represents the role of a member in a circle +#[derive(Debug, Clone, Serialize, Deserialize)] +pub enum Role { + Admin, + Stakeholder, + Member, + Contributor, + Guest, +} + +/// Member represents a member of a circle +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Member { + pub id: u32, // unique id + pub emails: Vec, // list of emails + pub name: String, // name of the member + pub description: String, // optional description + pub role: Role, // role of the member in the circle + pub contact_ids: Vec, // IDs of contacts linked to this member + pub wallet_ids: Vec, // IDs of wallets owned by this member +} + +impl Member { + /// Create a new member + pub fn new(id: u32, name: String, description: String, role: Role) -> Self { + Self { + id, + emails: Vec::new(), + name, + description, + role, + contact_ids: Vec::new(), + wallet_ids: Vec::new(), + } + } + + /// Add an email to this member + pub fn add_email(&mut self, email: String) { + if !self.emails.contains(&email) { + self.emails.push(email); + } + } + + /// Link a contact to this member + pub fn link_contact(&mut self, contact_id: u32) { + if !self.contact_ids.contains(&contact_id) { + self.contact_ids.push(contact_id); + } + } + + /// Link a wallet to this member + pub fn link_wallet(&mut self, wallet_id: u32) { + if !self.wallet_ids.contains(&wallet_id) { + self.wallet_ids.push(wallet_id); + } + } + + /// Returns a map of index keys for this member + pub fn index_keys(&self) -> HashMap { + let mut keys = HashMap::new(); + keys.insert("name".to_string(), self.name.clone()); + keys + } +} + +// Implement Storable trait (provides default dump/load) +impl Storable for Member {} + +// Implement SledModel trait +impl SledModel for Member { + fn get_id(&self) -> String { + self.id.to_string() + } + + fn db_prefix() -> &'static str { + "member" + } +} \ No newline at end of file diff --git a/herodb/src/models/circle/mod.rs b/herodb/src/models/circle/mod.rs index b47d562..2f578c4 100644 --- a/herodb/src/models/circle/mod.rs +++ b/herodb/src/models/circle/mod.rs @@ -1,9 +1,13 @@ pub mod circle; +pub mod member; pub mod name; +pub mod wallet; // Re-export all model types for convenience -pub use circle::{Circle, Member, Role}; +pub use circle::Circle; +pub use member::{Member, Role}; pub use name::{Name, Record, RecordType}; +pub use wallet::{Wallet, Asset}; // Re-export database components from db module pub use crate::db::{SledDB, SledDBError, SledDBResult, Storable, SledModel, DB}; diff --git a/herodb/src/models/circle/wallet.rs b/herodb/src/models/circle/wallet.rs new file mode 100644 index 0000000..ff4b5e1 --- /dev/null +++ b/herodb/src/models/circle/wallet.rs @@ -0,0 +1,84 @@ +use serde::{Deserialize, Serialize}; +use crate::db::{SledModel, Storable}; +use std::collections::HashMap; + +/// Asset represents a cryptocurrency asset in a wallet +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Asset { + pub name: String, // Asset name (e.g., "USDC") + pub amount: f64, // Amount of the asset +} + +impl Asset { + /// Create a new asset + pub fn new(name: String, amount: f64) -> Self { + Self { + name, + amount, + } + } +} + +/// Wallet represents a cryptocurrency wallet +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Wallet { + pub id: u32, // unique id + pub name: String, // name of the wallet + pub description: String, // optional description + pub blockchain_name: String, // name of the blockchain + pub pubkey: String, // public key of the wallet + pub assets: Vec, // assets in the wallet +} + +impl Wallet { + /// Create a new wallet + pub fn new(id: u32, name: String, description: String, blockchain_name: String, pubkey: String) -> Self { + Self { + id, + name, + description, + blockchain_name, + pubkey, + assets: Vec::new(), + } + } + + /// Set an asset in the wallet (replaces if exists, adds if not) + pub fn set_asset(&mut self, name: String, amount: f64) { + // Check if the asset already exists + if let Some(asset) = self.assets.iter_mut().find(|a| a.name == name) { + // Update the amount + asset.amount = amount; + } else { + // Add a new asset + self.assets.push(Asset::new(name, amount)); + } + } + + /// Get the total value of all assets in the wallet + pub fn total_value(&self) -> f64 { + self.assets.iter().map(|a| a.amount).sum() + } + + /// Returns a map of index keys for this wallet + pub fn index_keys(&self) -> HashMap { + let mut keys = HashMap::new(); + keys.insert("name".to_string(), self.name.clone()); + keys.insert("blockchain".to_string(), self.blockchain_name.clone()); + keys + } +} + +// Implement Storable trait (provides default dump/load) +impl Storable for Wallet {} + +// Implement SledModel trait +impl SledModel for Wallet { + fn get_id(&self) -> String { + self.id.to_string() + } + + fn db_prefix() -> &'static str { + "wallet" + } +} \ No newline at end of file diff --git a/herodb/src/models/instructions.md b/herodb/src/models/instructions.md new file mode 100644 index 0000000..3a2cfc7 --- /dev/null +++ b/herodb/src/models/instructions.md @@ -0,0 +1,18 @@ +in @src/models/circle/circle.rs + +- member us now new rootobject, check implementation +- a member is linked to one or more contacts id's (from src/models/mcc/contacts.rs) +- a member has one or more wallets + + +in@src/models/biz add a ticket module + +user can have more than 1 ticket which is to ask support from the org + +a ticket has following fields + +- subject +- description +- creation/update date +- assignees (based on memberid see above) +- \ No newline at end of file