square_api_client/models/
list_cards_parameters.rs1use super::enums::SortOrder;
4
5const DEFAULT_SORT_ORDER: SortOrder = SortOrder::Asc;
6
7#[derive(Clone, Debug)]
9pub struct ListCardsParameters {
10 pub cursor: String,
15 pub customer_id: String,
18 pub include_disabled: bool,
20 pub reference_id: String,
22 pub sort_order: SortOrder,
25}
26
27impl ListCardsParameters {
28 pub fn to_query_string(&self) -> String {
29 self.to_string()
30 }
31}
32
33impl Default for ListCardsParameters {
34 fn default() -> Self {
35 Self {
36 cursor: Default::default(),
37 customer_id: Default::default(),
38 include_disabled: Default::default(),
39 reference_id: Default::default(),
40 sort_order: DEFAULT_SORT_ORDER,
41 }
42 }
43}
44
45impl From<ListCardsParameters> for String {
46 fn from(list_cards_parameters: ListCardsParameters) -> Self {
47 list_cards_parameters.to_string()
48 }
49}
50
51impl ToString for ListCardsParameters {
52 fn to_string(&self) -> String {
53 let mut params = Vec::new();
54
55 if !self.cursor.is_empty() {
56 params.push(format!("cursor={}", self.cursor));
57 }
58
59 if !self.customer_id.is_empty() {
60 params.push(format!("customer_id={}", self.customer_id));
61 }
62
63 if self.include_disabled {
64 params.push(String::from("include_disabled=true"));
65 }
66
67 if !self.reference_id.is_empty() {
68 params.push(format!("reference_id={}", self.reference_id));
69 }
70
71 if self.sort_order != DEFAULT_SORT_ORDER {
72 params.push(format!("sort_order={}", serde_json::to_string(&self.sort_order).unwrap()));
73 }
74
75 if params.is_empty() {
76 String::new()
77 } else {
78 format!("?{}", params.join("&"))
79 }
80 }
81}