rust_woocommerce/models/
product_reviews.rs

1use crate::controllers::Entity;
2use chrono::NaiveDateTime;
3use serde::{Deserialize, Serialize};
4
5use crate::controllers::product_reviews::{
6    NoEmail, NoId, ProductReviewCreateBuilder, ProductReviewUpdateBuilder,
7};
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct ProductReview {
10    /// Unique identifier for the resource.
11    pub id: i32,
12    /// The date the review was created, in the site's timezone.
13    pub date_created: NaiveDateTime,
14    /// The date the review was created, as GMT.
15    pub date_created_gmt: NaiveDateTime,
16    /// Unique identifier for the product that the review belongs to.
17    pub product_id: i32,
18    /// Status of the review. Options: approved, hold, spam, unspam, trash and untrash. Defaults to approved.
19    pub status: ReviewStatus,
20    /// Reviewer name.
21    pub reviewer: String,
22    /// Reviewer email.
23    pub reviewer_email: String,
24    /// The content of the review.
25    pub review: String,
26    /// Review rating (0 to 5).
27    pub rating: i32,
28    /// Shows if the reviewer bought the product or not.
29    pub verified: bool,
30}
31impl Entity for ProductReview {
32    fn endpoint() -> String {
33        String::from("products/reviews/")
34    }
35
36    fn child_endpoint(parent_id: i32) -> String {
37        let _ = parent_id;
38        String::new()
39    }
40}
41impl ProductReview {
42    pub fn create() -> ProductReviewCreateBuilder<NoId, NoEmail> {
43        ProductReviewCreateBuilder::default()
44    }
45    pub fn update() -> ProductReviewUpdateBuilder {
46        ProductReviewUpdateBuilder::default()
47    }
48}
49#[derive(Debug, Clone, Serialize, Deserialize, Default)]
50#[serde(rename_all = "lowercase")]
51pub enum ReviewStatus {
52    #[default]
53    Approved,
54    Hold,
55    Spam,
56    Unspam,
57    Trash,
58    Untrash,
59}