inventory.rs (2554B)
1 //! Product inventory models 2 //! 3 //! This module defines inventory/stock management data models. 4 5 use bigdecimal::BigDecimal; 6 use chrono::{DateTime, Utc}; 7 use serde::{Deserialize, Serialize}; 8 use sqlx::FromRow; 9 use uuid::Uuid; 10 11 /// Inventory with pricing information (from v_product_inventory_pricing view) 12 /// 13 /// This combines inventory and pricing data for API responses. 14 #[derive(Debug, Serialize, Deserialize, FromRow)] 15 pub struct InventoryWithPricing { 16 // Product reference 17 pub product_uuid: Uuid, 18 pub product_asin: Option<String>, 19 20 // Inventory 21 pub stock_quantity: i32, 22 pub reserved_quantity: Option<i32>, 23 pub available_quantity: Option<i32>, 24 pub stock_status: Option<String>, 25 26 // Pricing 27 pub final_price: Option<BigDecimal>, 28 pub initial_price: Option<BigDecimal>, 29 pub currency: Option<String>, 30 pub discount_percentage: Option<BigDecimal>, 31 pub discount: Option<String>, 32 33 // Timestamps 34 pub last_restocked_at: Option<DateTime<Utc>>, 35 pub price_updated_at: Option<DateTime<Utc>>, 36 } 37 38 /// Query parameters for inventory listing 39 #[derive(Debug, Deserialize)] 40 pub struct InventoryQueryParams { 41 // Pagination 42 pub page: Option<i32>, 43 pub page_size: Option<i32>, 44 45 // Filters 46 pub stock_status: Option<String>, 47 pub product_uuid: Option<Uuid>, 48 pub min_stock: Option<i32>, 49 pub max_stock: Option<i32>, 50 } 51 52 /// Paginated inventory response 53 #[derive(Debug, Serialize)] 54 pub struct InventoryResponse { 55 pub inventory: Vec<InventoryWithPricing>, 56 pub total_count: i64, 57 pub page: i32, 58 pub page_size: i32, 59 pub total_pages: i32, 60 } 61 62 /// Request body for updating stock quantity 63 #[derive(Debug, Deserialize)] 64 pub struct UpdateStockRequest { 65 pub quantity: i32, 66 pub reorder_level: Option<i32>, 67 pub reorder_quantity: Option<i32>, 68 } 69 70 /// Request body for reserving stock 71 #[derive(Debug, Deserialize)] 72 pub struct ReserveStockRequest { 73 pub product_uuid: Uuid, 74 pub quantity: i32, 75 } 76 77 /// Request body for releasing reserved stock 78 #[derive(Debug, Deserialize)] 79 pub struct ReleaseStockRequest { 80 pub product_uuid: Uuid, 81 pub quantity: i32, 82 } 83 84 /// Request body for confirming a sale 85 #[derive(Debug, Deserialize)] 86 pub struct ConfirmSaleRequest { 87 pub product_uuid: Uuid, 88 pub quantity: i32, 89 pub order_uuid: Uuid, 90 } 91 92 /// Response for stock operations 93 #[derive(Debug, Serialize)] 94 pub struct StockOperationResponse { 95 pub success: bool, 96 pub message: String, 97 pub product_uuid: Uuid, 98 pub available_quantity: Option<i32>, 99 }