rust_woocommerce/models/
product_attributes.rs

1use crate::controllers::Entity;
2use serde::{Deserialize, Serialize};
3
4use crate::controllers::product_attributes::{
5    AttributeCreateBuilder, AttributeUpdateBuilder, NoName,
6};
7use crate::controllers::products::{AttributeDTOBuilder, NoOptions};
8
9/// Product attribute properties
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct Attribute {
12    /// Unique identifier for the resource.
13    pub id: i32,
14    /// Attribute name.
15    pub name: String,
16    /// An alphanumeric identifier for the resource unique to its type.
17    pub slug: String,
18    /// Type of attribute. By default, only select is supported.
19    #[serde(rename = "type")]
20    pub attribute_type: AttributeType,
21    /// Default sort order. Options: menu_order, name, name_num and id. Default is menu_order.
22    pub order_by: AttributeSortOrder,
23    /// Enable/Disable attribute archives. Default is false.
24    pub has_archives: bool,
25}
26impl Entity for Attribute {
27    fn endpoint() -> String {
28        String::from("products/attributes/")
29    }
30
31    fn child_endpoint(parent_id: i32) -> String {
32        let _ = parent_id;
33        String::new()
34    }
35}
36impl Attribute {
37    pub fn create() -> AttributeCreateBuilder<NoName> {
38        AttributeCreateBuilder::default()
39    }
40    pub fn update() -> AttributeUpdateBuilder {
41        AttributeUpdateBuilder::default()
42    }
43    pub fn builder() -> AttributeDTOBuilder<NoName, NoOptions> {
44        AttributeDTOBuilder::default()
45    }
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize, Default)]
49#[serde(rename_all = "lowercase")]
50pub enum AttributeType {
51    #[default]
52    Select,
53}
54#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
55#[serde(rename_all = "snake_case")]
56pub enum AttributeSortOrder {
57    #[default]
58    MenuOrder,
59    Name,
60    NameNum,
61    Id,
62}