1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use crate::SchemaExample;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};

#[derive(Serialize, Deserialize, Clone, Debug, Default, JsonSchema)]
#[schemars(example = "Self::example")]
pub struct ItemCount {
    /// The amount of items with this `value`.
    pub count: u32,
    /// The value of the field that it is grouped by.
    /// The value is `total` when no group by is given.
    /// The type varies depending on the group_by field type.
    pub value: Value,
}

impl ItemCount {
    pub fn new() -> Self {
        Self::default()
    }
}

impl SchemaExample for ItemCount {
    fn example() -> Self {
        Self {
            count: 60,
            value: json!("Tundra"),
        }
    }
}