#[derive(Debug, Clone)]
pub struct QueryParamsBuilder {
skip_count: Option<(String, String)>,
omit_total_items: Option<(String, String)>, order_by: Option<(String, String)>,
max_items: Option<(String, String)>,
where_filter: Option<(String, String)>,
include: Option<(String, String)>,
fields: Option<(String, String)>,
relative_path: Option<(String, String)>,
}
impl QueryParamsBuilder {
pub fn new() -> Self {
QueryParamsBuilder {
skip_count: None,
omit_total_items: None,
order_by: None,
max_items: None,
where_filter: None,
include: None,
fields: None,
relative_path: None,
}
}
pub fn set_skip_count(mut self, value: Option<&u32>) -> Self {
if let Some(skip) = value {
self.skip_count = Some(("skipCount".to_string(), skip.to_string()));
}
self
}
pub fn set_omit_total_items(mut self, value: Option<&bool>) -> Self {
if let Some(omit) = value {
self.omit_total_items = Some(("omitTotalItems".to_string(), omit.to_string()));
}
self
}
pub fn push_order_by(mut self, value: Option<&str>) -> Self {
if let Some(order_val) = value {
match self.order_by {
Some(orders) => {
let mut order_fields = orders.1.clone();
order_fields.push_str(&format!(",{}", order_val));
self.order_by = Some(("orderBy".to_string(), order_fields));
},
None => self.order_by = Some(("orderBy".to_string(), order_val.to_string()))
}
}
self
}
pub fn set_max_items(mut self, value: Option<&u32>) -> Self {
if let Some(max) = value {
self.max_items = Some(("maxItems".to_string(), max.to_string()));
}
self
}
pub fn set_where_filter(mut self, value: Option<&String>) -> Self {
if let Some(filter) = value {
self.where_filter = Some(("where".to_string(), filter.to_string()));
}
self
}
pub fn push_field(mut self, value: Option<&str>) -> Self {
if let Some(field_val) = value {
match self.fields {
Some(fields) => {
let mut field_fields = fields.1.clone();
field_fields.push_str(&format!(",{}", field_val));
self.fields = Some(("fields".to_string(), field_fields));
},
None => self.fields = Some(("fields".to_string(), field_val.to_string()))
}
}
self
}
pub fn push_include(mut self, value: Option<&str>) -> Self {
if let Some(include_val) = value {
match self.include {
Some(include) => {
let mut include_fields = include.1.clone();
include_fields.push_str(&format!(",{}", include_val));
self.include = Some(("include".to_string(), include_fields));
},
None => self.include = Some(("include".to_string(), include_val.to_string()))
}
}
self
}
pub fn set_relative_path(mut self, value: Option<&String>) -> Self {
if let Some(filter) = value {
self.relative_path = Some(("relativePath".to_string(), filter.to_string()));
}
self
}
pub fn get_skip_count(&mut self) -> &Option<(String, String)> { &self.skip_count }
pub fn get_omit_total_items(&mut self) -> &Option<(String, String)> { &self.omit_total_items }
pub fn get_order_by(&mut self) -> &Option<(String, String)> { &self.order_by }
pub fn get_max_items(&mut self) -> &Option<(String, String)> { &self.max_items }
pub fn get_where_filter(&mut self) -> &Option<(String, String)> { &self.where_filter }
pub fn get_fields(&mut self) -> &Option<(String,String)> { &self.fields }
pub fn get_include(&mut self) -> &Option<(String, String)> { &self.include }
pub fn get_relative_path(&mut self) -> &Option<(String, String)> { &self.relative_path }
pub fn build(&mut self) -> Vec<(String, String)> {
let mut vector = Vec::new();
if let Some(skip_count) = &self.skip_count {
vector.push(skip_count.clone());
};
if let Some(omit_total_items) = &self.omit_total_items {
vector.push(omit_total_items.clone());
}
if let Some(order) = &self.order_by {
vector.push(order.clone());
};
if let Some(max_items) = &self.max_items {
vector.push(max_items.clone());
};
if let Some(where_filter) = &self.where_filter {
vector.push(where_filter.clone());
};
if let Some(fields) = &self.fields {
vector.push(fields.clone());
};
if let Some(include) = &self.include {
vector.push(include.clone());
};
if let Some(relative_path) = &self.relative_path {
vector.push(relative_path.clone());
};
vector
}
}