1.9 KiB
1.9 KiB
Business Models Example
This example demonstrates the business models in HeroDB, showcasing a complete business transaction flow from product definition to payment processing.
Features Demonstrated
- Product Definition: Creating two types of server node products with different components and pricing
- Component Definition: Defining the parts that make up each server node (CPU, RAM, Storage, GPU)
- Pricing Setup: Setting up prices for products using the Currency model
- Product Availability: Checking which products can be purchased based on their status and availability
- Sales Process: Simulating a customer purchasing a product
- Invoice Generation: Creating an invoice for the sale
- Payment Processing: Processing a payment for the invoice and updating its status
Business Flow
The example follows this business flow:
Define Products → Check Availability → Customer Purchase → Generate Invoice → Process Payment
Models Used
- Product & ProductComponent: For defining server nodes and their components
- Customer: For representing the buyer
- Sale & SaleItem: For recording the purchase transaction
- Invoice & InvoiceItem: For billing the customer
- Payment: For recording the payment
Running the Example
To run this example, use:
cargo run --bin dbexample_biz
The output will show each step of the business process with relevant details.
Key Concepts
- Builder Pattern: All models use builders for flexible object creation
- Status Tracking: Sales and invoices have status enums to track their state
- Relationship Modeling: The example shows how different business entities relate to each other
- Financial Calculations: Demonstrates tax and total calculations
This example provides a template for implementing business logic in your own applications using HeroDB.