1use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
7#[serde(rename_all = "camelCase")]
8pub struct PageInfo {
9 pub limit: Option<i64>,
10 pub offset: Option<i64>,
11 pub has_next_page: bool,
12 pub has_previous_page: bool,
13}
14
15#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
16#[serde(rename_all = "camelCase")]
17pub struct Page<T> {
18 pub items: Vec<T>,
19 pub total_count: Option<i64>,
20 pub page_info: PageInfo,
21}
22
23impl<T> Page<T> {
24 pub fn new(items: Vec<T>, page_info: PageInfo) -> Self {
25 Self {
26 items,
27 total_count: None,
28 page_info,
29 }
30 }
31
32 pub fn with_total_count(mut self, total_count: Option<i64>) -> Self {
33 self.total_count = total_count;
34 self
35 }
36}