loom_rpc_handler/dto/
pagination.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use serde::Deserialize;
use utoipa::IntoParams;

const fn _page_default() -> usize {
    1
}
const fn _limit_default() -> usize {
    20
}

#[derive(Debug, Deserialize, IntoParams)]
pub struct Pagination {
    #[serde(default = "_page_default")]
    pub page: usize,
    #[serde(default = "_limit_default")]
    pub limit: usize,
}

impl Pagination {
    pub fn start(&self) -> usize {
        if self.page == 0 {
            return 0;
        }
        (self.page - 1) * self.limit
    }
}