rust_woocommerce/models/
product_attributes.rs1use 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#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct Attribute {
12 pub id: i32,
14 pub name: String,
16 pub slug: String,
18 #[serde(rename = "type")]
20 pub attribute_type: AttributeType,
21 pub order_by: AttributeSortOrder,
23 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}