square_api_client/models/
list_customers_parameters.rs1use super::enums::{SortCustomersField, SortOrder};
4
5const DEFAULT_SORT_ORDER: SortOrder = SortOrder::Asc;
6const DEFAULT_SORT_CUSTOMER_FIELD: SortCustomersField = SortCustomersField::CreatedAt;
7
8#[derive(Clone, Debug)]
10pub struct ListCustomersParameters {
11 pub cursor: String,
16 pub sort_order: SortOrder,
19 pub sort_field: SortCustomersField,
24}
25
26impl ListCustomersParameters {
27 pub fn to_query_string(&self) -> String {
28 self.to_string()
29 }
30}
31
32impl From<ListCustomersParameters> for String {
33 fn from(list_customers_parameters: ListCustomersParameters) -> Self {
34 list_customers_parameters.to_string()
35 }
36}
37impl Default for ListCustomersParameters {
38 fn default() -> Self {
39 Self {
40 cursor: Default::default(),
41 sort_order: DEFAULT_SORT_ORDER,
42 sort_field: DEFAULT_SORT_CUSTOMER_FIELD,
43 }
44 }
45}
46
47impl ToString for ListCustomersParameters {
48 fn to_string(&self) -> String {
49 let mut params = Vec::new();
50
51 if !self.cursor.is_empty() {
52 params.push(format!("cursor={}", self.cursor));
53 }
54
55 if self.sort_field != DEFAULT_SORT_CUSTOMER_FIELD {
56 params.push(format!("sort_field={}", self.sort_field.to_string()));
57 }
58
59 if self.sort_order != DEFAULT_SORT_ORDER {
60 params.push(format!("sort_order={}", serde_json::to_string(&self.sort_order).unwrap()));
61 }
62
63 if params.is_empty() {
64 String::new()
65 } else {
66 format!("?{}", params.join("&"))
67 }
68 }
69}