1use serde::Deserialize;
2
3#[derive(Debug, Clone)]
5pub struct Page<T> {
6 pub items: Vec<T>,
8 pub current_page: i64,
10 pub total_pages: Option<i64>,
12 pub total_count: Option<i64>,
14}
15
16impl<T> Page<T> {
17 pub fn has_next_page(&self) -> bool {
19 match self.total_pages {
20 Some(tp) => self.current_page < tp,
21 None => false,
22 }
23 }
24}
25
26#[derive(Debug, Clone, Deserialize)]
28#[serde(rename_all = "camelCase")]
29pub struct OffsetPageInfo {
30 pub current_page: i64,
31 pub total_pages: Option<i64>,
32 pub total_count: Option<i64>,
33}
34
35#[derive(Debug, Clone, Deserialize)]
39#[serde(rename_all = "camelCase")]
40pub struct Connection<T> {
41 pub edges: Vec<Edge<T>>,
42 pub page_info: OffsetPageInfo,
43}
44
45#[derive(Debug, Clone, Deserialize)]
47pub struct Edge<T> {
48 pub node: T,
49}
50
51impl<T> Connection<T> {
52 pub fn into_page(self) -> Page<T> {
54 Page {
55 items: self.edges.into_iter().map(|e| e.node).collect(),
56 current_page: self.page_info.current_page,
57 total_pages: self.page_info.total_pages,
58 total_count: self.page_info.total_count,
59 }
60 }
61}