rust_woocommerce/models/
product_categories.rs1use 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 pub id: i32,
11 pub name: String,
13 pub slug: String,
15 pub parent: i32,
17 pub description: String,
19 pub display: DisplayOption,
21 pub image: Option<ProductImage>,
23 pub menu_order: i32,
25 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}