lexoffice_cli/actions/
paginated.rs1use lexoffice::model::Page;
2use lexoffice::request::RequestWithState;
3use lexoffice::request::{Endpoint, Paginated};
4use lexoffice::Result;
5use serde::de::DeserializeOwned;
6use structopt::StructOpt;
7
8#[derive(Debug, StructOpt)]
9pub struct PaginatedOpt {
10 #[structopt(short, long)]
12 page: Option<usize>,
13 #[structopt(short, long)]
15 size: Option<usize>,
16}
17
18impl PaginatedOpt {
19 pub async fn exec<T, U>(
20 &self,
21 request: RequestWithState<T, U>,
22 ) -> Result<Page<T>>
23 where
24 RequestWithState<T, U>: Paginated + Endpoint + Send + Sync + Clone,
25 T: DeserializeOwned + Send + Sync + Clone + 'static,
26 U: Send + Sync + Clone + 'static,
27 {
28 let page = self.page.unwrap_or(0);
29 if let Some(size) = self.size {
30 request.page_size(page, size).await
31 } else {
32 request.page(page).await
33 }
34 }
35}