This commit is contained in:
2025-03-31 09:32:03 +02:00
parent 79330ef8f5
commit 05ab2b68f4
10 changed files with 0 additions and 450 deletions

View File

@@ -1,10 +0,0 @@
[package]
name = "zaz_models"
version = "0.1.0"
edition = "2021"
description = "Rust port of Zaz models"
[dependencies]
chrono = "0.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

View File

@@ -1,68 +0,0 @@
# Zaz Models (Rust)
This project is a Rust port of the Zaz models originally implemented in V.
## Overview
This library provides data models for the Zaz application, focusing on core business entities. It includes models for:
- Users
- Companies
- Shareholders
- Meetings
- Products
- Sales
- Votes
## Models
Each model includes:
- Type-safe struct definitions
- Proper enums for status fields
- Serde serialization/deserialization support
- Index key functionality for database operations
## Usage
Add this to your `Cargo.toml`:
```toml
[dependencies]
zaz_models = { path = "path/to/zaz/modelsrust" }
```
Example usage:
```rust
use zaz_models::{User, Company, Vote, VoteStatus};
use chrono::Utc;
// Create a new user
let user = User {
id: 1,
name: "John Doe".to_string(),
email: "john@example.com".to_string(),
password: "secure_hash".to_string(),
company: "Acme Inc".to_string(),
role: "Admin".to_string(),
created_at: Utc::now(),
updated_at: Utc::now(),
};
// Access index keys
let keys = user.index_keys();
assert_eq!(keys.get("id").unwrap(), "1");
assert_eq!(keys.get("email").unwrap(), "john@example.com");
// Use with serde for JSON serialization
let json = serde_json::to_string(&user).unwrap();
println!("{}", json);
// Deserialize from JSON
let deserialized_user: User = serde_json::from_str(&json).unwrap();
assert_eq!(deserialized_user.name, "John Doe");
```
## Notes
This port focuses on the data structures only. The original encoding/decoding functionality has been replaced with serde serialization/deserialization.

View File

@@ -1,54 +0,0 @@
use crate::shareholder::{Shareholder};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
/// CompanyStatus represents the status of a company
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum CompanyStatus {
Active,
Inactive,
Suspended,
}
/// BusinessType represents the type of a business
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum BusinessType {
Coop,
Single,
Twin,
Starter,
Global,
}
/// Company represents a company registered in the Freezone
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Company {
pub id: u32,
pub name: String,
pub registration_number: String,
pub incorporation_date: DateTime<Utc>,
pub fiscal_year_end: String,
pub email: String,
pub phone: String,
pub website: String,
pub address: String,
pub business_type: BusinessType,
pub industry: String,
pub description: String,
pub status: CompanyStatus,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub shareholders: Vec<Shareholder>,
}
impl Company {
/// Returns the keys to be indexed for this company
pub fn index_keys(&self) -> HashMap<String, String> {
let mut keys = HashMap::new();
keys.insert("id".to_string(), self.id.to_string());
keys.insert("name".to_string(), self.name.clone());
keys.insert("registration_number".to_string(), self.registration_number.clone());
keys
}
}

View File

@@ -1,16 +0,0 @@
pub mod user;
pub mod vote;
pub mod company;
pub mod meeting;
pub mod product;
pub mod sale;
pub mod shareholder;
// Re-export all model types for convenience
pub use user::User;
pub use vote::{Vote, VoteOption, Ballot, VoteStatus};
pub use company::Company;
pub use meeting::Meeting;
pub use product::Product;
pub use sale::Sale;
pub use shareholder::Shareholder;

View File

@@ -1,68 +0,0 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
/// MeetingStatus represents the status of a meeting
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum MeetingStatus {
Scheduled,
Completed,
Cancelled,
}
/// AttendeeRole represents the role of an attendee in a meeting
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum AttendeeRole {
Coordinator,
Member,
Secretary,
Participant,
Advisor,
Admin,
}
/// AttendeeStatus represents the status of an attendee's participation
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum AttendeeStatus {
Confirmed,
Pending,
Declined,
}
/// Attendee represents an attendee of a board meeting
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Attendee {
pub id: u32,
pub meeting_id: u32,
pub user_id: u32,
pub name: String,
pub role: AttendeeRole,
pub status: AttendeeStatus,
pub created_at: DateTime<Utc>,
}
/// Meeting represents a board meeting of a company or other meeting
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Meeting {
pub id: u32,
pub company_id: u32,
pub title: String,
pub date: DateTime<Utc>,
pub location: String,
pub description: String,
pub status: MeetingStatus,
pub minutes: String,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub attendees: Vec<Attendee>,
}
impl Meeting {
/// Returns the keys to be indexed for this meeting
pub fn index_keys(&self) -> HashMap<String, String> {
let mut keys = HashMap::new();
keys.insert("id".to_string(), self.id.to_string());
keys.insert("company_id".to_string(), self.company_id.to_string());
keys
}
}

View File

@@ -1,63 +0,0 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
/// Currency represents a monetary value with amount and currency code
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Currency {
pub amount: f64,
pub currency_code: String,
}
/// ProductType represents the type of a product
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ProductType {
Product,
Service,
}
/// ProductStatus represents the status of a product
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ProductStatus {
Available,
Unavailable,
}
/// ProductComponent represents a component of a product
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProductComponent {
pub id: u32,
pub name: String,
pub description: String,
pub quantity: i32,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
/// Product represents a product or service offered by the Freezone
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Product {
pub id: u32,
pub name: String,
pub description: String,
pub price: Currency,
pub type_: ProductType,
pub category: String,
pub status: ProductStatus,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub max_amount: u16, // means allows us to define how many max of this there are
pub purchase_till: DateTime<Utc>,
pub active_till: DateTime<Utc>, // after this product no longer active if e.g. a service
pub components: Vec<ProductComponent>,
}
impl Product {
/// Returns the keys to be indexed for this product
pub fn index_keys(&self) -> HashMap<String, String> {
let mut keys = HashMap::new();
keys.insert("id".to_string(), self.id.to_string());
keys.insert("name".to_string(), self.name.clone());
keys
}
}

View File

@@ -1,50 +0,0 @@
use crate::product::Currency;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
/// SaleStatus represents the status of a sale
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum SaleStatus {
Pending,
Completed,
Cancelled,
}
/// SaleItem represents an item in a sale
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SaleItem {
pub id: u32,
pub sale_id: u32,
pub product_id: u32,
pub name: String,
pub quantity: i32,
pub unit_price: Currency,
pub subtotal: Currency,
pub active_till: DateTime<Utc>, // after this product no longer active if e.g. a service
}
/// Sale represents a sale of products or services
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Sale {
pub id: u32,
pub company_id: u32,
pub buyer_name: String,
pub buyer_email: String,
pub total_amount: Currency,
pub status: SaleStatus,
pub sale_date: DateTime<Utc>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub items: Vec<SaleItem>,
}
impl Sale {
/// Returns the keys to be indexed for this sale
pub fn index_keys(&self) -> HashMap<String, String> {
let mut keys = HashMap::new();
keys.insert("id".to_string(), self.id.to_string());
keys.insert("company_id".to_string(), self.company_id.to_string());
keys
}
}

View File

@@ -1,36 +0,0 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
/// ShareholderType represents the type of shareholder
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ShareholderType {
Individual,
Corporate,
}
/// Shareholder represents a shareholder of a company
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Shareholder {
pub id: u32,
pub company_id: u32,
pub user_id: u32,
pub name: String,
pub shares: f64,
pub percentage: f64,
pub type_: ShareholderType,
pub since: DateTime<Utc>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
impl Shareholder {
/// Returns the keys to be indexed for this shareholder
pub fn index_keys(&self) -> HashMap<String, String> {
let mut keys = HashMap::new();
keys.insert("id".to_string(), self.id.to_string());
keys.insert("company_id".to_string(), self.company_id.to_string());
keys.insert("user_id".to_string(), self.user_id.to_string());
keys
}
}

View File

@@ -1,26 +0,0 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
/// User represents a user in the Freezone Manager system
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct User {
pub id: u32,
pub name: String,
pub email: String,
pub password: String,
pub company: String, // here its just a best effort
pub role: String,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
impl User {
/// Returns the keys to be indexed for this user
pub fn index_keys(&self) -> HashMap<String, String> {
let mut keys = HashMap::new();
keys.insert("id".to_string(), self.id.to_string());
keys.insert("email".to_string(), self.email.clone());
keys
}
}

View File

@@ -1,59 +0,0 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
/// VoteStatus represents the status of a vote
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum VoteStatus {
Open,
Closed,
Cancelled,
}
/// Vote represents a voting item in the Freezone
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Vote {
pub id: u32,
pub company_id: u32,
pub title: String,
pub description: String,
pub start_date: DateTime<Utc>,
pub end_date: DateTime<Utc>,
pub status: VoteStatus,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub options: Vec<VoteOption>,
pub ballots: Vec<Ballot>,
pub private_group: Vec<u32>, // user id's only people who can vote
}
/// VoteOption represents an option in a vote
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VoteOption {
pub id: u8,
pub vote_id: u32,
pub text: String,
pub count: i32,
pub min_valid: i32, // min votes we need to make total vote count
}
/// The vote as done by the user
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Ballot {
pub id: u32,
pub vote_id: u32,
pub user_id: u32,
pub vote_option_id: u8,
pub shares_count: i32,
pub created_at: DateTime<Utc>,
}
impl Vote {
/// Returns the keys to be indexed for this vote
pub fn index_keys(&self) -> HashMap<String, String> {
let mut keys = HashMap::new();
keys.insert("id".to_string(), self.id.to_string());
keys.insert("company_id".to_string(), self.company_id.to_string());
keys
}
}