fistinc_paging/
query_params.rs1use serde::{Deserialize, Serialize};
2
3pub trait QueryParams: Send + Sync {
4 fn limit(&self) -> i64;
5 fn offset(&self) -> i64;
6}
7
8const DEFAULT_OFFSET: Option<i64> = Some(0);
9const DEFAULT_LIMIT: Option<i64> = Some(25);
10
11#[derive(Debug, Serialize, Deserialize)]
12pub struct QueryParamsImpl {
13 pub limit: Option<i64>,
14 pub offset: Option<i64>,
15}
16
17impl QueryParamsImpl {
18 pub fn new() -> Self {
19 QueryParamsImpl {
20 limit: DEFAULT_LIMIT,
21 offset: DEFAULT_OFFSET,
22 }
23 }
24}
25
26impl Default for QueryParamsImpl {
27 fn default() -> Self {
28 Self::new()
29 }
30}
31
32impl QueryParams for QueryParamsImpl {
33 fn limit(&self) -> i64 {
34 self.limit.or(DEFAULT_LIMIT).unwrap_or_default()
35 }
36 fn offset(&self) -> i64 {
37 self.offset.or(DEFAULT_OFFSET).unwrap_or_default()
38 }
39}