rust_woocommerce/models/
product_categories.rs

1use crate::controllers::Entity;
2use serde::{Deserialize, Serialize};
3
4use crate::controllers::product_categories::{CategoryCreate, CategoryUpdate};
5
6use super::products::ProductImage;
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct Category {
9    /// Unique identifier for the resource.
10    pub id: i32,
11    /// Category name.
12    pub name: String,
13    /// An alphanumeric identifier for the resource unique to its type.
14    pub slug: String,
15    /// The ID for the parent of the resource.
16    pub parent: i32,
17    /// HTML description of the resource.
18    pub description: String,
19    /// Category archive display type. Options: default, products, subcategories and both. Default is default.
20    pub display: DisplayOption,
21    /// Image data.
22    pub image: Option<ProductImage>,
23    /// Menu order, used to custom sort the resource.
24    pub menu_order: i32,
25    /// Number of published products for the resource. READ-ONLY
26    pub count: i32,
27}
28impl Category {
29    pub fn create<T: ToString>(name: T) -> CategoryCreate {
30        CategoryCreate::new(name)
31    }
32    pub fn update() -> CategoryUpdate {
33        CategoryUpdate::default()
34    }
35}
36
37impl Entity for Category {
38    fn endpoint() -> String {
39        String::from("products/categories/")
40    }
41    fn child_endpoint(parent_id: i32) -> String {
42        let _ = parent_id;
43        String::new()
44    }
45}
46#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
47#[serde(rename_all = "lowercase")]
48pub enum DisplayOption {
49    #[default]
50    Default,
51    Products,
52    Subcategories,
53    Both,
54}