alfresco_sdk/alfresco/
params.rs

1#[derive(Debug, Clone)]
2pub struct QueryParamsBuilder {
3    skip_count: Option<(String, String)>,
4    omit_total_items: Option<(String, String)>, // bool
5    order_by: Option<(String, String)>,
6    max_items: Option<(String, String)>,
7    where_filter: Option<(String, String)>,
8    include: Option<(String, String)>,
9    fields: Option<(String, String)>,
10    relative_path: Option<(String, String)>,
11}
12
13impl QueryParamsBuilder {
14    pub fn new() -> Self {
15        QueryParamsBuilder {
16            skip_count: None,
17            omit_total_items: None,
18            order_by: None,
19            max_items: None,
20            where_filter: None,
21            include: None,
22            fields: None,
23            relative_path: None,
24        }
25    }
26
27    pub fn set_skip_count(mut self, value: Option<&u32>) -> Self {
28        if let Some(skip) = value {
29            self.skip_count = Some(("skipCount".to_string(), skip.to_string()));
30        }
31
32        self
33    }
34
35    pub fn set_omit_total_items(mut self, value: Option<&bool>) -> Self {
36        if let Some(omit) = value {
37            self.omit_total_items = Some(("omitTotalItems".to_string(), omit.to_string()));
38        }
39
40        self
41    }
42
43    pub fn push_order_by(mut self, value: Option<&str>) -> Self {
44        if let Some(order_val) = value {
45            match self.order_by {
46                Some(orders) => {
47                    let mut order_fields = orders.1.clone();
48                    order_fields.push_str(&format!(",{}", order_val));
49                    self.order_by = Some(("orderBy".to_string(), order_fields));
50                },
51                None => self.order_by = Some(("orderBy".to_string(), order_val.to_string()))
52            }
53        }
54
55        self
56    }
57
58    pub fn set_max_items(mut self, value: Option<&u32>) -> Self {
59        if let Some(max) = value {
60            self.max_items = Some(("maxItems".to_string(), max.to_string()));
61        }
62
63        self
64    }
65
66    pub fn set_where_filter(mut self, value: Option<&String>) -> Self {
67        if let Some(filter) = value {
68            self.where_filter = Some(("where".to_string(), filter.to_string()));
69        }
70
71        self
72    }
73
74    pub fn push_field(mut self, value: Option<&str>) -> Self {
75        if let Some(field_val) = value {
76            match self.fields {
77                Some(fields) => {
78                    let mut field_fields = fields.1.clone();
79                    field_fields.push_str(&format!(",{}", field_val));
80                    self.fields = Some(("fields".to_string(), field_fields));
81                },
82                None => self.fields = Some(("fields".to_string(), field_val.to_string()))
83            }
84        }
85
86        self
87    }
88
89    pub fn push_include(mut self, value: Option<&str>) -> Self {
90        if let Some(include_val) = value {
91            match self.include {
92                Some(include) => {
93                    let mut include_fields = include.1.clone();
94                    include_fields.push_str(&format!(",{}", include_val));
95                    self.include = Some(("include".to_string(), include_fields));
96                },
97                None => self.include = Some(("include".to_string(), include_val.to_string()))
98            }
99        }
100
101        self
102    }
103
104    pub fn set_relative_path(mut self, value: Option<&String>) -> Self {
105        if let Some(filter) = value {
106            self.relative_path = Some(("relativePath".to_string(), filter.to_string()));
107        }
108
109        self
110    }
111
112    pub fn get_skip_count(&mut self) -> &Option<(String, String)> { &self.skip_count }
113
114    pub fn get_omit_total_items(&mut self) -> &Option<(String, String)> { &self.omit_total_items }
115
116    pub fn get_order_by(&mut self) -> &Option<(String, String)> { &self.order_by }
117
118    pub fn get_max_items(&mut self) -> &Option<(String, String)> { &self.max_items }
119
120    pub fn get_where_filter(&mut self) -> &Option<(String, String)> { &self.where_filter }
121
122    pub fn get_fields(&mut self) -> &Option<(String,String)> { &self.fields }
123
124    pub fn get_include(&mut self) -> &Option<(String, String)> { &self.include }
125
126    pub fn get_relative_path(&mut self) -> &Option<(String, String)> { &self.relative_path }
127
128
129
130    pub fn build(&mut self) -> Vec<(String, String)> {
131        let mut vector = Vec::new();
132
133        if let Some(skip_count) = &self.skip_count {
134            vector.push(skip_count.clone());
135        };
136
137        if let Some(omit_total_items) = &self.omit_total_items {
138            vector.push(omit_total_items.clone());
139        }
140
141        if let Some(order) = &self.order_by {
142            vector.push(order.clone());
143        };
144
145        if let Some(max_items) = &self.max_items {
146            vector.push(max_items.clone());
147        };
148
149        if let Some(where_filter) = &self.where_filter {
150            vector.push(where_filter.clone());
151        };
152
153        if let Some(fields) = &self.fields {
154            vector.push(fields.clone());
155        };
156
157        if let Some(include) = &self.include {
158            vector.push(include.clone());
159        };
160
161        if let Some(relative_path) = &self.relative_path {
162            vector.push(relative_path.clone());
163        };
164
165        vector
166    }
167}