squareup/models/
list_invoices_parameters.rs

1//! Query parameters for the List Invoices API
2
3use std::fmt::Display;
4
5/// This is a model struct for ListInvoicesParameters (query parameters)
6#[derive(Clone, Debug, Default)]
7pub struct ListInvoicesParameters {
8    /// The ID of the location for which to list invoices.
9    pub location_id: String,
10    /// A pagination cursor returned by a previous call to this endpoint. Provide this cursor to
11    /// retrieve the next set of results for your original query.
12    ///
13    /// For more information, see
14    /// [Pagination](https://developer.squareup.com/docs/basics/api101/pagination).
15    pub cursor: Option<String>,
16    /// The maximum number of invoices to return (200 is the maximum `limit`). If not provided, the
17    /// server uses a default limit of 100 invoices.
18    pub limit: Option<i32>,
19}
20
21impl ListInvoicesParameters {
22    pub fn to_query_string(&self) -> String {
23        self.to_string()
24    }
25}
26
27impl From<ListInvoicesParameters> for String {
28    fn from(list_invoices_parameters: ListInvoicesParameters) -> Self {
29        list_invoices_parameters.to_string()
30    }
31}
32
33impl Display for ListInvoicesParameters {
34    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35        let mut params = Vec::new();
36
37        if !self.location_id.is_empty() {
38            params.push(format!("location_id={}", &self.location_id));
39        }
40
41        if let Some(cursor) = &self.cursor {
42            params.push(format!("cursor={}", cursor));
43        }
44
45        if let Some(limit) = self.limit {
46            params.push(format!("limit={}", limit));
47        }
48
49        let str = if params.is_empty() {
50            String::new()
51        } else {
52            format!("?{}", params.join("&"))
53        };
54        write!(f, "{}", str)
55    }
56}