backbone_graphql/
pagination.rs1use async_graphql::*;
4use serde::Serialize;
5
6#[derive(Debug, Clone, SimpleObject, Serialize)]
8pub struct PaginationInfo {
9 pub total: i64,
10 pub page: i32,
11 pub limit: i32,
12 pub total_pages: i32,
13}
14
15impl PaginationInfo {
16 pub fn new(total: u64, page: u32, limit: u32) -> Self {
17 let total = total as i64;
18 let page = page as i32;
19 let limit = limit as i32;
20 let total_pages = if limit == 0 {
21 0
22 } else {
23 ((total as f64) / (limit as f64)).ceil() as i32
24 };
25 Self {
26 total,
27 page,
28 limit,
29 total_pages,
30 }
31 }
32}