ferric_fred/
series_list_request.rs1use crate::{Client, OrderBy, Result, SeriesSearchResults, SortOrder};
2
3#[derive(Debug, Clone)]
26#[must_use = "a SeriesListRequest does nothing until you call `.send()`"]
27pub struct SeriesListRequest<'a> {
28 client: &'a Client,
29 path: &'static str,
31 facet: (&'static str, String),
34 order_by: Option<OrderBy>,
35 sort_order: Option<SortOrder>,
36 limit: Option<u32>,
37 offset: Option<u32>,
38}
39
40impl<'a> SeriesListRequest<'a> {
41 pub(crate) fn new(
42 client: &'a Client,
43 path: &'static str,
44 facet_key: &'static str,
45 facet_value: String,
46 ) -> Self {
47 Self {
48 client,
49 path,
50 facet: (facet_key, facet_value),
51 order_by: None,
52 sort_order: None,
53 limit: None,
54 offset: None,
55 }
56 }
57
58 pub fn order_by(mut self, order_by: OrderBy) -> Self {
60 self.order_by = Some(order_by);
61 self
62 }
63
64 pub fn sort_order(mut self, order: SortOrder) -> Self {
66 self.sort_order = Some(order);
67 self
68 }
69
70 pub fn limit(mut self, limit: u32) -> Self {
72 self.limit = Some(limit);
73 self
74 }
75
76 pub fn offset(mut self, offset: u32) -> Self {
78 self.offset = Some(offset);
79 self
80 }
81
82 pub async fn send(self) -> Result<SeriesSearchResults> {
89 self.client.execute_series_list(&self).await
90 }
91
92 pub(crate) fn path(&self) -> &'static str {
94 self.path
95 }
96
97 pub(crate) fn query_params(&self) -> Vec<(&'static str, String)> {
100 let mut params: Vec<(&'static str, String)> = vec![(self.facet.0, self.facet.1.clone())];
101 if let Some(order_by) = self.order_by {
102 params.push(("order_by", order_by.query_code().to_owned()));
103 }
104 if let Some(order) = self.sort_order {
105 params.push(("sort_order", order.query_code().to_owned()));
106 }
107 if let Some(limit) = self.limit {
108 params.push(("limit", limit.to_string()));
109 }
110 if let Some(offset) = self.offset {
111 params.push(("offset", offset.to_string()));
112 }
113 params
114 }
115}
116
117impl crate::paginate::sealed::Sealed for SeriesListRequest<'_> {}
118impl crate::paginate::Paginate for SeriesListRequest<'_> {
119 type Page = SeriesSearchResults;
120 const MAX_PAGE: u32 = 1000;
121 fn requested_limit(&self) -> Option<u32> {
122 self.limit
123 }
124 fn requested_offset(&self) -> Option<u32> {
125 self.offset
126 }
127 fn with_paging(self, limit: u32, offset: u32) -> Self {
128 self.limit(limit).offset(offset)
129 }
130 fn send_page(self) -> impl std::future::Future<Output = Result<Self::Page>> + Send {
131 self.send()
132 }
133}