use serde_json::{Map, Value};
#[derive(Debug, Clone, Copy)]
pub enum SortOrder {
Asc,
Desc,
}
impl SortOrder {
pub(crate) fn as_str(self) -> &'static str {
match self {
SortOrder::Asc => "asc",
SortOrder::Desc => "desc",
}
}
}
#[derive(Debug, Clone)]
pub struct Sort {
value: Value,
}
impl Sort {
pub(crate) fn new(field: &str, order: SortOrder) -> Self {
let mut order_body = Map::new();
order_body.insert(
"order".to_string(),
Value::String(order.as_str().to_string()),
);
let mut outer = Map::new();
outer.insert(field.to_string(), Value::Object(order_body));
Self {
value: Value::Object(outer),
}
}
pub(crate) fn raw(value: Value) -> Self {
Self { value }
}
pub(crate) fn to_value(&self) -> Value {
self.value.clone()
}
}