Skip to main content

mcp_procurement/
store.rs

1use std::collections::HashMap;
2use std::sync::{Arc, Mutex};
3use crate::types::*;
4
5fn uid() -> String { uuid::Uuid::new_v4().to_string()[..8].to_string() }
6
7#[derive(Clone)]
8pub struct Store {
9    pub suppliers: Arc<Mutex<HashMap<String, Supplier>>>,
10    pub purchase_orders: Arc<Mutex<HashMap<String, PurchaseOrder>>>,
11    pub rfqs: Arc<Mutex<HashMap<String, Rfq>>>,
12    pub receipts: Arc<Mutex<Vec<GoodsReceipt>>>,
13    pub contracts: Arc<Mutex<HashMap<String, Contract>>>,
14    pub invoices: Arc<Mutex<Vec<Invoice>>>,
15    pub budgets: Arc<Mutex<Vec<Budget>>>,
16    pub diversity: Arc<Mutex<Vec<SupplierDiversity>>>,
17    pub catalogs: Arc<Mutex<Vec<CatalogItem>>>,
18}
19
20impl Store {
21    pub fn new() -> Self {
22        Self {
23            suppliers: Arc::new(Mutex::new(HashMap::new())),
24            purchase_orders: Arc::new(Mutex::new(HashMap::new())),
25            rfqs: Arc::new(Mutex::new(HashMap::new())),
26            receipts: Arc::new(Mutex::new(Vec::new())),
27            contracts: Arc::new(Mutex::new(HashMap::new())),
28            invoices: Arc::new(Mutex::new(Vec::new())),
29            budgets: Arc::new(Mutex::new(Vec::new())),
30            diversity: Arc::new(Mutex::new(Vec::new())),
31            catalogs: Arc::new(Mutex::new(Vec::new())),
32        }
33    }
34    pub fn new_id(prefix: &str) -> String { format!("{}_{}", prefix, uid()) }
35}