rust_woocommerce/controllers/
product_attribute_terms.rs

1use serde::{Deserialize, Serialize};
2use serde_with::skip_serializing_none;
3
4#[skip_serializing_none]
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct AttributeTermCreate {
7    name: String,
8    slug: Option<String>,
9    description: Option<String>,
10    menu_order: Option<i32>,
11}
12#[derive(Default)]
13pub struct AttributeTermCreateBuilder<N> {
14    name: N,
15    slug: Option<String>,
16    description: Option<String>,
17    menu_order: Option<i32>,
18}
19#[derive(Default)]
20pub struct WithName(String);
21#[derive(Default)]
22pub struct NoName;
23impl<N> AttributeTermCreateBuilder<N> {
24    /// Term name.
25    pub fn name(self, name: impl Into<String>) -> AttributeTermCreateBuilder<WithName> {
26        AttributeTermCreateBuilder {
27            name: WithName(name.into()),
28            slug: self.slug,
29            description: self.description,
30            menu_order: self.menu_order,
31        }
32    }
33    /// An alphanumeric identifier for the resource unique to its type.
34    pub fn slug(mut self, slug: impl Into<String>) -> Self {
35        let _ = self.slug.insert(slug.into());
36        self
37    }
38    /// HTML description of the resource.
39    pub fn description(mut self, description: impl Into<String>) -> Self {
40        let _ = self.description.insert(description.into());
41        self
42    }
43    /// Menu order, used to custom sort the resource.
44    pub fn menu_order(mut self, menu_order: i32) -> Self {
45        let _ = self.menu_order.insert(menu_order);
46        self
47    }
48}
49impl AttributeTermCreateBuilder<WithName> {
50    pub fn build(self) -> AttributeTermCreate {
51        AttributeTermCreate {
52            name: self.name.0,
53            slug: self.slug,
54            description: self.description,
55            menu_order: self.menu_order,
56        }
57    }
58}
59#[skip_serializing_none]
60#[derive(Debug, Clone, Serialize, Deserialize)]
61pub struct AttributeTermUpdate {
62    id: Option<i32>,
63    name: Option<String>,
64    slug: Option<String>,
65    description: Option<String>,
66    menu_order: Option<i32>,
67}
68#[derive(Default)]
69pub struct AttributeTermUpdateBuilder {
70    id: Option<i32>,
71    name: Option<String>,
72    slug: Option<String>,
73    description: Option<String>,
74    menu_order: Option<i32>,
75}
76impl AttributeTermUpdateBuilder {
77    /// Unique identifier for the resource.
78    pub fn id(&mut self, id: i32) -> &mut Self {
79        let _ = self.id.insert(id);
80        self
81    }
82    /// Term name.
83    pub fn name(&mut self, name: impl Into<String>) -> &mut Self {
84        let _ = self.name.insert(name.into());
85        self
86    }
87    /// An alphanumeric identifier for the resource unique to its type.
88    pub fn slug(mut self, slug: impl Into<String>) -> Self {
89        let _ = self.slug.insert(slug.into());
90        self
91    }
92    /// HTML description of the resource.
93    pub fn description(mut self, description: impl Into<String>) -> Self {
94        let _ = self.description.insert(description.into());
95        self
96    }
97    /// Menu order, used to custom sort the resource.
98    pub fn menu_order(mut self, menu_order: i32) -> Self {
99        let _ = self.menu_order.insert(menu_order);
100        self
101    }
102    pub fn build(&self) -> AttributeTermUpdate {
103        AttributeTermUpdate {
104            id: self.id,
105            name: self.name.to_owned(),
106            slug: self.slug.to_owned(),
107            description: self.description.to_owned(),
108            menu_order: self.menu_order,
109        }
110    }
111}