rust_woocommerce/models/
mod.rs

1use serde_with::skip_serializing_none;
2
3pub mod coupons;
4pub mod customers;
5pub mod data;
6pub mod order_notes;
7pub mod orders;
8pub mod payment_gateways;
9pub mod product_attribute_terms;
10pub mod product_attributes;
11pub mod product_categories;
12pub mod product_reviews;
13pub mod product_shipping_classes;
14pub mod product_tags;
15pub mod product_variations;
16pub mod products;
17pub mod refunds;
18pub mod reports;
19pub mod settings;
20pub mod shipping_methods;
21pub mod shipping_zone_locations;
22pub mod shipping_zone_methods;
23pub mod shipping_zones;
24pub mod tax_classes;
25pub mod tax_rates;
26pub mod webhooks;
27#[skip_serializing_none]
28#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
29pub struct MetaData {
30    pub id: Option<i32>,
31    pub key: String,
32    pub value: serde_json::Value,
33}
34#[skip_serializing_none]
35#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
36pub struct BatchObject<O: serde::Serialize> {
37    pub create: Option<Vec<O>>,
38    pub update: Option<Vec<O>>,
39    pub delete: Option<Vec<O>>,
40}
41impl<O> BatchObject<O>
42where
43    O: serde::Serialize,
44{
45    pub fn builder() -> BatchObjectBuilder<O>
46    where
47        O: serde::Serialize + Clone,
48    {
49        BatchObjectBuilder::default()
50    }
51}
52#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
53pub struct BatchObjectBuilder<O: serde::Serialize> {
54    pub create: Option<Vec<O>>,
55    pub update: Option<Vec<O>>,
56    pub delete: Option<Vec<O>>,
57}
58impl<O> Default for BatchObjectBuilder<O>
59where
60    O: serde::Serialize + Clone,
61{
62    fn default() -> Self {
63        Self {
64            create: None,
65            update: None,
66            delete: None,
67        }
68    }
69}
70impl<O> BatchObjectBuilder<O>
71where
72    O: serde::Serialize + Clone,
73{
74    pub fn add_create(&mut self, object: O) -> &mut Self {
75        self.create.get_or_insert(vec![]).push(object);
76        self
77    }
78    pub fn add_update(&mut self, object: O) -> &mut Self {
79        self.update.get_or_insert(vec![]).push(object);
80        self
81    }
82    pub fn add_delete(&mut self, object: O) -> &mut Self {
83        self.delete.get_or_insert(vec![]).push(object);
84        self
85    }
86    pub fn extend_create(&mut self, vec: Vec<O>) -> &mut Self {
87        self.create.get_or_insert(vec![]).extend(vec);
88        self
89    }
90    pub fn extend_update(&mut self, vec: Vec<O>) -> &mut Self {
91        self.update.get_or_insert(vec![]).extend(vec);
92        self
93    }
94    pub fn extend_delete(&mut self, vec: Vec<O>) -> &mut Self {
95        self.delete.get_or_insert(vec![]).extend(vec);
96        self
97    }
98    pub fn build(&self) -> BatchObject<O> {
99        BatchObject {
100            create: self.create.clone(),
101            update: self.update.clone(),
102            delete: self.delete.clone(),
103        }
104    }
105}